#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1000000007;

#define nosync            ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define prec(x)           cout<<fixed<<setprecision((x));
#define deb(x)            cout<<#x<<" "<<x<<endl;
#define deba(x)           cout<<#x<<": "; for(auto e:x) cout<<e<<" ";  cout<<endl;

#define test            int t; cin>>t; while(t--)
#define f(i,l,r)        for(i=l;i<=r;i++)
#define rep(i,n)        f(i,0,n-1)

#define all(c)          c.begin(), c.end()
#define pb             push_back
#define mp             make_pair
#define ff            first
#define ss            second
#define pii           pair<ll,ll>
#define vi           vector<ll>
#define vvi          vector<vi>



void buildmn(ll tree[],ll node,ll a[],ll start, ll end)
{
    if(start==end)
    {
        tree[node]=a[start];
        return ;
    }
    else{
            ll mid=(start+end)/2;
        buildmn(tree,2*node,a,start,mid);
     buildmn(tree,2*node+1,a,mid+1,end);
    }
    tree[node]=min(tree[2*node],tree[2*node+1]);
}

void buildmx(ll tree[],ll node,ll a[],ll start, ll end)
{
    if(start==end)
    {
        tree[node]=a[start];
        return ;
    }
    else{
            ll mid=(start+end)/2;
        buildmx(tree,2*node,a,start,mid);
     buildmx(tree,2*node+1,a,mid+1,end);
    }
    tree[node]=max(tree[2*node],tree[2*node+1]);
}

ll update(ll tree[],ll node,ll start, ll end,ll i,ll x)
{
    if(start==end)
        tree[node]=x;
    else
    {
         ll mid=(start+end)/2;
         if(i>=start && i<=mid) update(tree,2*node,start,mid,i,x);
         else update(tree,2*node+1,mid+1,end,i,x);

    tree[node]=min(tree[2*node],tree[2*node+1]);
    }

}


ll querymn(ll tree[],ll node,ll start, ll end,ll l, ll r)
{
    if(l >end || r<start)
        return 9999999;
    if(start>=l && end<=r)
        return tree[node];
     ll mid=(start+end)/2;
     return min(querymn(tree,2*node,start,mid,l,r),querymn(tree,2*node+1,mid+1,end,l,r));
}


ll querymx(ll tree[],ll node,ll start, ll end,ll l, ll r)
{
    if(l >end || r<start)
        return -9999999;
    if(start>=l && end<=r)
        return tree[node];
     ll mid=(start+end)/2;
     return max(querymx(tree,2*node,start,mid,l,r),querymx(tree,2*node+1,mid+1,end,l,r));
}





void solve()
{ 
	int i,j;
	
ll n,m; cin>>n>>m;
string s; cin>>s;


ll pre[s.size()+1];

pre[0]=0;

for(int i=0;i<s.size();i++)
{
	if(s[i]=='+') pre[i+1]=pre[i]+1;
	else pre[i+1]=pre[i]-1;


}


 // Height of segment tree 
    int x = (int)(ceil(log2(n))); 
  
    // Maximum size of segment tree 
    int max_size = 2*(int)pow(2, x) - 1; 
   ll treemn[max_size+1];
     ll treemx[max_size+1];
   buildmn(treemn,1,pre,0,n);
    buildmx(treemx,1,pre,0,n);



int l,r;
rep(i,m)
{
	cin>>l>>r;

int mn,mx;
mn= querymn(treemn,1,0,n,0,l-1);
mx= querymx(treemx,1,0,n,0,l-1);


int sum= pre[r]-pre[l-1];
int mn2,mx2;
mn2= querymn(treemn,1,0,n,r+1,n);
mx2= querymx(treemx,1,0,n,r+1,n);


mn2-= sum;
mx2-= sum;

int ansmn= min(mn,mn2);
int ansmx= max(mx,mx2);

cout<<ansmx- ansmn+1<<endl;

}







}



int main()
{  

nosync
   
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif


test solve();

}