#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 4 ;
int a[N] , prefMin[N] , prefMax[N] , suffixMin[N] , suffixMax[N];
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t ;
    cin >> t ;
    while(t--){
         int n , m , q  , sum =0 , s1 = 0 , s2 =0;
         cin >> n >> m ;
         string s;
         cin >> s;
         s = '#' + s ;
         for(int i = 1 ; i<=n ;++i){
            if(s[i] == '+')
                sum++ ;
            else
                sum--;
            a[i] = sum;
            prefMin[i] = min(prefMin[i-1] ,sum);
            prefMax[i] = max(prefMax[i-1] , sum);
         }
         suffixMin[n+1] = suffixMax[n+1] = 0 ;
         sum = 0;
         for(int i = n ; i>=1; --i){
            if(s[i] == '+')
                s1++ , s2++;
            else
               s1-- , s2--;
            s1 = min(s1 , 0);
            s2 = max(s2 ,0);
            suffixMin[i] = s1;
            suffixMax[i] = s2;
         }
         while(m--){
            int l , r ;
            cin >> l >> r;
            int maxi = max(prefMax[l-1] , suffixMax[r+1] + a[l-1]) ;
			int mini = min(prefMin[l-1] , suffixMin[r+1] + a[l-1]) ;
			cout<<maxi+abs(mini)+1<< '\n' ;
         }


    }
    return 0;
}
