#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, p[N], rp[N], pre[2][N], suf[2][N];
char s[N];
void solve()
{
	scanf("%d%d%s", &n, &m, s+1);
	for(int i=1; i<=n; i++)
	{
		if(s[i]=='+') p[i] = p[i-1] + 1;
		else p[i] = p[i-1] - 1;
	}
	for(int i=1; i<=n; i++) pre[0][i] = max(pre[0][i-1], p[i]), pre[1][i] = min(pre[1][i-1], p[i]);
	suf[0][n+1] = suf[1][n+1] = p[n];
	for(int i=n; i>=1; i--) suf[0][i] = max(suf[0][i+1], p[i]), suf[1][i] = min(suf[1][i+1], p[i]);
	while(m--)
	{
		int l, r; scanf("%d%d", &l, &r);
		if(l==1&&r==n) puts("1");
		else if(l==1) printf("%d\n", suf[0][r+1]-suf[1][r+1]+1+(p[r]<suf[1][r+1]||p[r]>suf[0][r+1]));
		else if(r==n) printf("%d\n", pre[0][l-1]-pre[1][l-1]+1);
		else 
		{
			int mx = pre[0][l-1], mn = pre[1][l-1];
			int x = p[l-1] - p[r];
			mx = max(mx, x+suf[0][r+1]), mn = min(mn, x+suf[1][r+1]);
			printf("%d\n", mx-mn+1);
		}
	}
}
int main()
{
	int _; scanf("%d", &_);
	while(_--) solve();	
	return 0;
}