#include <iostream>
#include <cstring>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int T;
	cin >> T;
	int N, M, Lmax[200001], Lmin[200001], Lsum[200001], Rmax[200001], Rmin[200001], Rsum[200001];
	char signs[200001];
	for (int t = 0; t < T; t++)
	{
		cin >> N >> M;
		cin >> signs;

		Lmax[0] = 0, Lmin[0] = 0, Lsum[0] = 0;
		for (int i = 1; i <= N; i++)
		{
			if (signs[i - 1] == '+')
			{
				Lsum[i] = Lsum[i - 1] + 1;
				Lmax[i] = (Lmax[i - 1] > Lsum[i] ? Lmax[i - 1] : Lsum[i]);
				Lmin[i] = Lmin[i - 1];
			}
			else
			{
				Lsum[i] = Lsum[i - 1] - 1;
				Lmax[i] = Lmax[i - 1];
				Lmin[i] = (Lmin[i - 1] < Lsum[i] ? Lmin[i - 1] : Lsum[i]);
			}
		}
		Rmax[N] = 0, Rmin[N] = 0, Rsum[N] = 0;
		for (int i = N - 1; i >= 0; i--)
		{
			if (signs[i] == '+')
			{
				Rsum[i] = Rsum[i + 1] + 1;
				Rmax[i] = Rmax[i + 1] + 1;
				Rmin[i] = min(Rmin[i + 1] + 1, 0);
			}
			else
			{
				Rsum[i] = Rsum[i + 1] - 1;
				Rmax[i] = max(Rmax[i + 1] - 1, 0);
				Rmin[i] = Rmin[i + 1] - 1;
			}
		}

		for (int m = 0; m < M; m++)
		{
			int qL, qR;
			cin >> qL >> qR;
			int NowValue = Lsum[qL - 1], Max = Lmax[qL - 1], Min = Lmin[qL - 1];
			Max = (Max > NowValue + Rmax[qR] ? Max : NowValue + Rmax[qR]);
			Min = (Min < NowValue + Rmin[qR] ? Min : NowValue + Rmin[qR]);
			cout << Max - Min + 1 << "\n";
		}
	}

	return 0;
}