#include<bits/stdc++.h>
 
using namespace std; 
const int inf=0x3f3f3f3f;
typedef long long ll; 
const int N=2e5+7;
const ll mod=998244353;
  
char s[N];

int sum[N],maxn2[N],minn2[N],maxn1[N],minn1[N];

int main()
{   
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k,z;
        scanf("%d%d%s",&n,&k,s);
        for (int i = 1; i <= n; ++i)
        {
            if(s[i-1]=='+')sum[i]=sum[i-1]+1;
            else sum[i]=sum[i-1]-1;

            maxn1[i]=max(maxn1[i-1],sum[i]);
            minn1[i]=min(minn1[i-1],sum[i]);
        }
        maxn2[n]=minn2[n]=sum[n];
        for(int i=n-1;i>=0;i--){
            maxn2[i]=max(maxn2[i+1],sum[i]);
            minn2[i]=min(minn2[i+1],sum[i]);
        }
        while(k--){
            int l,r;
            scanf("%d%d",&l,&r);
            int maxn=maxn1[l-1],minn=minn1[l-1];
            if(maxn1[r]<=maxn1[n]){
                maxn=max(maxn,maxn2[r]-(sum[r]-sum[l-1]));
            }
            if(minn1[r]>=minn1[n]){
                minn=min(minn,minn2[r]-(sum[r]-sum[l-1]));
            } 
            cout<<maxn-minn+1<<endl;
        }
    }
    return 0;
}