#include <bits/stdc++.h>

#define ll                 long long
#define sf                 scanf
#define pf                 printf
#define nl                 printf("\n")
#define endl               '\n'
#define pb                 push_back
#define rep(i,a,b)         for(int i=a; i<b; i++)
#define repr(i,a,b)        for(int i=a; i>=b; i--)
#define TEST               int Test;cin>>Test;for(int _t=1;_t<=Test;_t++)
#define isValid(a,b,A,B)   (0<=a&&a<A) and (0<=b&&b<B)

using namespace std;

template <typename... T> void read(T &... args){ ((cin >> args), ...); }

void yes(){ pf("Yes\n"); }
void no() { pf("No\n"); }

typedef pair<int,int> Pr;

int arr[600005];
Pr tree[600005];

void makeTree(int node, int L, int R){
	if(L==R){
		tree[node] = Pr(arr[L],arr[L]);
		return;
	}
	int mid = L + (R-L)/2;
	int left = node*2;
	int right = node*2 + 1;
	makeTree(left,L,mid);
	makeTree(right,mid+1,R);
	tree[node] = Pr(min(tree[left].first,tree[right].first), max(tree[left].second,tree[right].second));
}

Pr Query(int node, int L, int R, int x, int y){
	if(R<x or y<L) return Pr(1e9, -1e9);
	if(x<=L and R<=y) return tree[node];
	int mid = L + (R-L)/2;
	int left = node*2;
	int right = node*2 + 1;
	Pr p1 = Query(left,L,mid,x,y);
	Pr p2 = Query(right,mid+1,R,x,y);
	return Pr(min(p1.first,p2.first), max(p1.second,p2.second));
}

int main()
{	
	int n,q,x,y;
	string str;
	TEST{
		read(n,q);
		getchar();
		read(str);
		int cnt = 0;
		rep(i,0,n){
			if(str[i]=='+') cnt++;
			else cnt--;
			arr[i+1] = cnt;
		}
		makeTree(1,1,n);
		while(q--){
			read(x,y);
			int res;
			if(x==1 and y==n){
				res = 1;
			}
			else if(y==n){
				Pr ans = Query(1,1,n,1,x-1);
				res = ans.second-ans.first+1;
				if(ans.first>0 or ans.second<0) res++;
			}
			else if(x==1){
				Pr ans = Query(1,1,n,y+1,n);
				ans.first -= arr[y];
				ans.second -= arr[y];
				res = ans.second-ans.first+1;
				if(ans.first>0 or ans.second<0) res++;
			}
			else{
				Pr ans1 = Query(1,1,n,1,x-1);
				Pr ans2 = Query(1,1,n,y+1,n);
				ans2.first = ans2.first-arr[y]+arr[x-1];
				ans2.second = ans2.second-arr[y]+arr[x-1];
				Pr ans = Pr(min(ans1.first,ans2.first),max(ans1.second,ans2.second));
				res = ans.second-ans.first+1;
				if(ans.first>0 or ans.second<0) res++;
				
			}
			pf("%d\n",res);
		}
	}
	return 0;
}
