#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int read()
{
	int res = 0,flag = 1;
	char ch = getchar();
	while(ch<'0' || ch>'9')
	{
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(ch>='0' && ch<='9')
	{
		res = (res<<3)+(res<<1)+(ch^48);//res*10+ch-'0';
		ch = getchar();
	}
	return res*flag;
}
const int maxn = 2e5+5;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-8;
struct node{
	int maxx,minn;
}a[maxn<<2];
int n,m,num[maxn],suf1[maxn],suf2[maxn];
char s[maxn];
bool flag;
void pushup(int root)
{
	a[root].maxx = max(a[root<<1].maxx,a[root<<1|1].maxx);
	a[root].minn = min(a[root<<1].minn,a[root<<1|1].minn);
}
void build(int root,int l,int r)
{
	if(l == r)
	{
		a[root].maxx = a[root].minn = num[l];
		return ;
	}
	int mid = l+r>>1;
	build(root<<1,l,mid);
	build(root<<1|1,mid+1,r);
	pushup(root);
}
int query_max(int root,int l,int r,int ql,int qr)
{
	if(l>qr || r<ql) return -inf;
	if(l>=ql && r<=qr) return a[root].maxx;
	int mid = l+r>>1;
	return max(query_max(root<<1,l,mid,ql,qr),query_max(root<<1|1,mid+1,r,ql,qr));
}
int query_min(int root,int l,int r,int ql,int qr)
{
	if(l>qr || r<ql) return inf;
	if(l>=ql && r<=qr) return a[root].minn;
	int mid = l+r>>1;
	return min(query_min(root<<1,l,mid,ql,qr),query_min(root<<1|1,mid+1,r,ql,qr));
}
int get_ans(int maxx,int minn)
{
	if(maxx<0 && minn<0) return -minn+1;
	if(maxx>0 && minn>0) return maxx+1;
	return maxx-minn+1;
}
int main()
{
	int t = read();
	while(t--)
	{
		n = read(),m = read();
		scanf("%s",s+1);
		int now = 0;
		for(int i = 1;i <= n;i++)
		{
			if(s[i] == '+') num[i] = ++now;
			else num[i] = --now;
		}
		build(1,1,n);
		suf1[n+1] = suf2[n+1] = 0;
		for(int i = n;i;i--)
			if(s[i] == '+') 
			{
				suf1[i] = suf1[i+1]+1;
				suf2[i] = suf2[i+1];
			}
			else {
				suf1[i] = suf1[i+1];
				suf2[i] = suf2[i+1]+1;
			}
		while(m--)
		{
			int l = read(),r = read();
			int maxx = l==1 ? 0 : query_max(1,1,n,1,l-1);
			int minn = l==1 ? 0 : query_min(1,1,n,1,l-1);
			int mmax = r==n ? 0 : query_max(1,1,n,r+1,n);
			int mmin = r==n ? 0 : query_min(1,1,n,r+1,n);
			int val = num[r]-num[l-1];
			mmax -= val,mmin -= val;
			if(r == n) printf("%d\n",get_ans(maxx,minn));
			else if(l == 1) printf("%d\n",get_ans(mmax,mmin));
			else printf("%d\n",get_ans(max(mmax,maxx),min(mmin,minn)));
		}
	}
	return 0;
}

     		 	 		  	     	       			