#include <bits/stdc++.h>       #define st first   #define nd second   #define pb push_back   #define BOOST ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);   #define PI 3.14159265359       using namespace std;       typedef long long ll;   constexpr ll MOD = 1000000007, sup = 29;   constexpr ll MOD_1 = 1234567891, sup_1 = 1009;   constexpr ll MOD_2 = 1000000009, sup_2 = 107;   constexpr int MXN = 200000+10, CZAPA = (1<<18), INF = 1000000000;      int n, m;      struct tree{    pair<int, int> tab[2*CZAPA+10];       void add(int leaf, int x){     int v = leaf + CZAPA;     tab[v] = {x, x};     v /= 2;     while(v >= 1){      tab[v].st = min(tab[2*v].st, tab[2*v+1].st);      tab[v].nd = max(tab[2*v].nd, tab[2*v+1].nd);      v /= 2;     }    }       pair<int, int> query(int a, int b, int v, int p, int q){     if(q < a || b < p)      return {INF, -INF};     if(p >= a && q <= b)      return tab[v];     int mid = (p+q)/2;     pair<int, int> x = query(a, b, 2*v, p, mid), y = query(a, b, 2*v+1, mid+1, q);     return {min(x.st, y.st), max(x.nd, y.nd)};    }       pair<int, int> query(int a, int b){     return query(a+CZAPA, b+CZAPA, 1, CZAPA, 2*CZAPA-1);    }   };      tree T;      int tab[MXN];         int main(){    BOOST;       int t;    cin>> t;    T.add(0, 0);    while(t--){     string s;      cin>> n >> m >> s;     for(int i=1; i<=n; i++){      tab[i] = tab[i-1];      if(s[i-1] ==  - )       tab[i]--;      else       tab[i]++;      T.add(i, tab[i]);      //cout<< tab[i] <<    ;     }     //cout<<   n ;     while(m--){      int a, b;      cin>> a >> b;      pair<int, int> x = T.query(0, a-1);      int sum = tab[b] - tab[a-1];      pair<int, int> y = T.query(b+1, n);      if(y.st == INF){       cout<< abs(x.st-x.nd)+1 <<   n ;       continue;      }      y.st -= sum;      y.nd -= sum;      pair<int, int> ans = {min(x.st, y.st), max(x.nd, y.nd)};      cout<< abs(ans.st-ans.nd)+1 <<   n ;      //cout<< x.st <<   ~   << x.nd <<  ,   << y.st <<   ~   << y.nd <<   n ;     }    }               return 0;   }   