#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int t,n,m;
string s;
int pre[maxn],bmx[maxn],bmn[maxn],fmx[maxn],fmn[maxn];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n>>m>>s;
		s=" "+s;
		pre[0]=bmx[0]=bmn[0]=0;
		for(int i=1;i<=n;i++)
		{
			if(s[i]=='+')
			{
				pre[i]=pre[i-1]+1;
			}
			else
			{
				pre[i]=pre[i-1]-1;
			}
			bmx[i]=max(bmx[i-1],pre[i]);
			bmn[i]=min(bmn[i-1],pre[i]);
		}
		fmx[n+1]=fmn[n+1]=0;
		for(int i=n;i>=1;i--)
		{
			if(s[i]=='+')
			{
				fmx[i]=fmx[i+1]+1;
				fmn[i]=min(0,fmn[i+1]+1);
			}
			else
			{
				fmx[i]=max(0,fmx[i+1]-1);
				fmn[i]=fmn[i+1]-1;
			}
		}
		while(m--)
		{
			int l,r;
			cin>>l>>r;
			cout<<max(bmx[l-1],pre[l-1]+fmx[r+1])-min(bmn[l-1],pre[l-1]+fmn[r+1])+1<<endl;
		}
	}
	return 0;
}