#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=1e9+7;
ll mul(ll a,ll b)
{
    return ((a%mod)*(b%mod))%mod;
}
ll add(ll a,ll b)
{
    return ((a%mod)+(b%mod))%mod;
}
ll sub(ll a,ll b)
{
    return ((a%mod)-(b%mod)+mod)%mod;
}
ll po(ll a, ll b)
{
    if(b==0)
    {
        return 1;
    }
    ll t=po(a,b/2);
    if(b%2)
    {
        return mul(t,mul(t,a));
    }
    else
    {
        return mul(t,t);
    }
}
ll  a[200005];
ll mseg[1000000];
ll maseg[1000000];
void mupd(ll s, ll e, ll i)
{
	if(s==e)
	{
		mseg[i]=a[s];
		return;
	}
	ll mi=s+(e-s)/2;
	mupd(s,mi,2*i+1);
	mupd(mi+1,e,2*i+2);
	mseg[i]=min(mseg[2*i+1],mseg[2*i+2]);
	return;
}
void maupd(ll s, ll e, ll i)
{
	if(s==e)
	{
		maseg[i]=a[s];
		return;
	}
	ll mi=s+(e-s)/2;
	maupd(s,mi,2*i+1);
	maupd(mi+1,e,2*i+2);
	maseg[i]=max(maseg[2*i+1],maseg[2*i+2]);
	return;
}
ll mir(ll s, ll e, ll i,ll chs, ll che)
{
	if(s>che || e<chs)
	{
		return 1e18;
	}
	if(s<=chs && e>=che)
	{
		return mseg[i];
	}
	ll mi=chs+(che-chs)/2;
	return min(mir(s,e,2*i+1,chs,mi),mir(s,e,2*i+2,mi+1,che));
}
ll mar(ll s, ll e, ll i,ll chs, ll che)
{
	if(s>che || e<chs)
	{
		return -1e18;
	}
	if(s<=chs && e>=che)
	{
		return maseg[i];
	}
	ll mi=chs+(che-chs)/2;
	return max(mar(s,e,2*i+1,chs,mi),mar(s,e,2*i+2,mi+1,che));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
    	ll n,q;
    	cin>>n>>q;
    	a[0]=0;
    	string s;
    	cin>>s;
    	for(ll i=0;i<n;i++)
    	{
    		if(s[i]=='-')
    		{
    			a[i+1]=a[i]-1;
    		}
    		else
    		{
    			a[i+1]=a[i]+1;
    		}
    		//cout<<a[i+1]<<" ";
    	}
    	//cout<<"\n";
    	mupd(0,n,0);
    	maupd(0,n,0);
    	while(q--)
    	{
    		ll l,r;
    		cin>>l>>r;
    		ll u1=mir(0,l-1,0,0,n);
    		ll u2=mar(0,l-1,0,0,n);;
    		ll s1=0,s2=0;
    		//cout<<u1<<" "<<u2<<"\n";
    		if(r+1<=n)
    		{
    		 s1=mir(r+1,n,0,0,n);
    		 s2=mar(r+1,n,0,0,n);;
    		 
    		 s1=s1-a[r];
    		 s2=s2-a[r];
    		}
    		//cout<<u1<<" "<<u2<<" "<<s1<<" "<<s2<<"\n";
    		ll mi=min((ll)0,u1);
    		ll ma=max((ll)0,u2);
    		mi=min(a[l-1]+s1,mi);
    		ma=max(a[l-1]+s2,ma);
    		cout<<ma-mi+1<<"\n";
    	}
    }
    return 0;
}