#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
	for (int i = 0; i < t; ++i) {
		int n, m;
		cin >> n >> m;
		string s;
		cin >> s;
		int sum[n + 1];
		sum[0] = 0;
		for (int j = 1; j <= n; ++j) {
			if (s[j - 1] == '+') {
				sum[j] = sum[j - 1] + 1;
			}
			else {
				sum[j] = sum[j - 1] - 1;	
			}
		}
		int max[n + 1], min[n + 1];
		max[0] = 0;
		min[0] = 0;
		for (int j = 1; j <= n; ++j) {
			if (sum[j] > max[j - 1]) {
				max[j] = sum[j];
			}
			else {
				max[j] = max[j - 1];
			}
			if (sum[j] < min[j - 1]) {
				min[j] = sum[j];
			}
			else {
				min[j] = min[j - 1];
			}
		}
		int maxb[n + 2], minb[n + 2];
		maxb[n + 1] = -1000000;
		minb[n + 1] = 1000000;
		for (int j = n; j > 0; --j) {
			if (sum[j] > maxb[j + 1]) {
				maxb[j] = sum[j];
			}
			else {
				maxb[j] = maxb[j + 1];
			}
			if (sum[j] < minb[j + 1]) {
				minb[j] = sum[j];
			}
			else {
				minb[j] = minb[j + 1];
			}
		}
		for (int j = 0; j < m; ++j) {
			int l, r;
			cin >> l >> r;
			if (r == n) {
				cout << max[l - 1] - min[l - 1] + 1 << endl;
			}
			else {
				int mina, maxa;
				if (min[l - 1] > minb[r + 1] - sum[r] + sum[l - 1]) {
					mina = minb[r + 1] - sum[r] + sum[l - 1];
				}
				else {
					mina = min[l - 1];
				}
				if (max[l - 1] > maxb[r + 1] - sum[r] + sum[l - 1]) {
					maxa = max[l - 1];
				}
				else {
					maxa = maxb[r + 1] - sum[r] + sum[l - 1];
				}
				cout << maxa - mina + 1 << endl;
			}
		}
	}
	return 0;
}
