//#pragma comment(linker, "/stack:102400000,102400000")

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <cassert>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define lson (k << 1)
#define rson (k << 1 | 1)
#define endl '\n'
#define MP make_pair
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "m", stdout)
#define io ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define what(x) cerr << #x << ": " << x << endl

template <typename T>
inline void read(T& x) {
	static char b, f;
	b = getchar();
	f = 1, x = 0;
	for (; !isdigit(b); b = getchar())
		if (b == '-') f = -1;
	for (; isdigit(b); b = getchar())
		x = (x << 1) + (x << 3) + b - '0';
	x *= f;
}
template <typename T, typename... Args>
inline void read(T& x, Args&... args) {
	read(x);
	read(args...);
}
ll qpow(ll q, ll n, ll mod) {
	ll ans = 1 % mod;
	while (n) {
		if (n & 1) ans = ans * q % mod;
		q = q * q % mod;
		n >>= 1;
	}
	return ans;
}
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

const ld eps = 1e-6;
const ld pi = acos(-1);
const ll lnf = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int dx[] = { 1, 0, -1, 0 }; //下 右 上 左
const int dy[] = { 0, 1, 0, -1 };
const char ds[] = "DRUL";
const int mod = 7 + 1e9;
const int N = 3 + 2e5;

char s[N];
int n, m;
int pre_max[N], suf_max[N];
int pre_min[N], suf_min[N];
int v[N];

void slv() {
	for (int i = 1; i <= n; ++i)
		v[i] = v[i - 1] + (s[i] == '+' ? 1 : -1);
	suf_min[n + 1] = inf;
	suf_max[n + 1] = -inf;
	for (int i = 1; i <= n; ++i) {
		pre_min[i] = min(pre_min[i - 1], v[i]);
		pre_max[i] = max(pre_max[i - 1], v[i]);
	}
	for (int i = n; i; --i) {
		suf_min[i] = min(suf_min[i + 1], v[i]);
		suf_max[i] = max(suf_max[i + 1], v[i]);
	}
	int L, R;
	while (m--) {
		cin >> L >> R;
		int mn = pre_min[L - 1];
		int mx = pre_max[L - 1];
		int sum = v[R] - v[L - 1];
		mn = min(mn, suf_min[R + 1] - sum);
		mx = max(mx, suf_max[R + 1] - sum);
		cout << mx - mn + 1 << endl;
	}
}

int main() {
	io;
	int T;
	cin >> T;
	while (T--) {
		cin >> n >> m;
		cin >> s + 1;
		slv();
	}
	return 0;
}