#include<bits/stdc++.h>

#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;



void solve(){
	
	int n,que;
	cin>>n>>que;
	
	string s;
	cin>>s;
	
	vector<int>v(n);
	for(int i=0;i<n;i++) v[i]=s[i]=='+'?1:-1;
	
	vector<pair<pii,int>> prefix(n);
	vector<pair<pii,int>> suffix(n);
	
	int val;
	int curMin;
	int curMax;
	
	{
		val=0;
		curMin=0;
		curMax=0;
		for(int i=0;i<n;i++){
			val+=v[i];
			curMin=min(val,curMin);
			curMax=max(val,curMax);
			prefix[i]=mp(mp(curMin,curMax),val);
		}
	}
	
	{
		val=0;
		curMin=0;
		curMax=0;
		for(int i=n-1;i>=0;i--){
			val-=v[i];
			curMin=min(val,curMin);
			curMax=max(val,curMax);
			suffix[i]=mp(mp(curMin,curMax),val);
		}	
	}
	
	while(que--){
		int l,r;
		cin>>l>>r;
		l--;
		r--;
		
		int a=l-1;
		int b=r+1;
		
		int cur=0;
		int retMin=0;
		int retMax=0;
//		cout<<"[] "<<a<<" "<<b<<endl;
		if(a>=0 && a<n){
			retMin=min(retMin,prefix[a].fi.fi);
			retMax=max(retMax,prefix[a].fi.se);
			cur=prefix[a].se;
		}
//		cout<<retMin<<" "<<retMax<<endl;
		if(b>=0 && b<n){
			retMin=min(retMin,suffix[b].fi.fi-(suffix[b].se-cur));
			retMax=max(retMax,suffix[b].fi.se-(suffix[b].se-cur));
		}
//		cout<<retMin<<" "<<retMax<<endl;
		cout<<retMax-retMin+1<<endl;
	}
	
	
	
}

int main(){
	
	fastio();
	
	int t=1;
	cin>>t;
	
	for(int tt=0;tt<t;tt++){
//		cout<<"Case "<<tt+1<<":\n";solve();
		solve();
	}
	
	return 0;
}