You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types: 

  * increase x by 1; 
  * decrease x by 1. 



You are given m queries of the following format: 

  * query l r — how many distinct values is x assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order? 

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.

Then the description of t testcases follows.

The first line of each testcase contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of instructions in the program and the number of queries.

The second line of each testcase contains a program — a string of n characters: each character is either '+' or '-' — increment and decrement instruction, respectively.

Each of the next m lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the description of the query.

The sum of n over all testcases doesn't exceed 2 ⋅ 10^5. The sum of m over all testcases doesn't exceed 2 ⋅ 10^5. 

Output

For each testcase print m integers — for each query l, r print the number of distinct values variable x is assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order.

Example

Input


2
8 4
-+--+--+
1 8
2 8
2 5
1 1
4 10
+-++
1 1
1 2
2 2
1 3
2 3
3 3
1 4
2 4
3 4
4 4


Output


1
2
4
4
3
3
4
2
3
2
1
2
2
2

Note

The instructions that remain for each query of the first testcase are: 

  1. empty program — x was only equal to 0; 
  2. "-" — x had values 0 and -1; 
  3. "---+" — x had values 0, -1, -2, -3, -2 — there are 4 distinct values among them; 
  4. "+--+--+" — the distinct values are 1, 0, -1, -2. 
#include <bits/stdc++.h>
using namespace std;
#define MODS 100005
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define ld long double
#define bigint int64_t
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define mp make_pair
#define pb push_back
#define test ll t;read(t);while(t--)
#define pll pair<ll,ll>
#define vvll vector<vector<ll>>
#define fst first
#define scd second
#define ins insert
#define line "\n"
#define yes "YES"
#define no "NO"

#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define forr(i,n) for(ll (i) = (n)-1 ; (i)>=0 ; --(i))
#define forab(i,a,b,c) for(ll (i) = a ; (i) <= (b) ; (i)+=(c))

template <typename T>
void read(T &x){
    cin >> x;
}
template <typename T , typename T0>
void read(T &x,T0 &y){
    cin >> x >> y;
}

template <typename T , typename T0 , typename T1>
void read(T &x,T0 &y,T1 &z){
    cin >> x >> y >> z;
}

template <typename T , typename T0 , typename T1 , typename T2>
void read(T &x,T0 &y,T1 &z,T2 &w){
    cin >> x >> y >> z >> w;
}

template <typename T , typename T0>
void read(pair< T , T0 > &p){
    cin >> p.fst >>p.scd;
}

template <typename T>
void read(vector< T > &oneD,ll n){
    forn(i,n)
    {
        ll x;
        read(x);
        oneD.push_back(x);
    }
}

template <typename T>
void read(T oneD[] , ll n){
    for(ll i=0;i<n;i++){
        read(oneD[i]);
    }
}

template <typename T>
void write(T &x){

    cout << x << " ";
}

template <typename T>
void wrtline(T &x){

    cout << x << line;
}

template <typename T , typename T0>
void write(T &x,T0 &y){
    cout << x << " " << y << "\n";
}

template <typename T , typename T0 , typename T1>
void write(T &x,T0 &y,T1 &z){
    cout << x << " " << y << " " << z << "\n";
}

template <typename T , typename T0 , typename T1 , typename T2>
void write(T &x,T0 &y,T1 &z,T2 &w){
    cout << x << " " << y << " " << z << " " << w << "\n";
}

template <typename T , typename T0>
void write(pair< T , T0 > &p){
    write(p.fst);
    write(p.scd);
    cout << line;
}

template <typename T>
void write(vector< T > &oneD,ll n){
    for(ll i=0;i<n;i++){
        cout<<oneD[i]<<" ";
    }
    cout << line;
}

template <typename T>
void write(T oneD[] ,int n){
    for(ll i=0;i<n;i++){
        write(oneD[i]);
    }
    cout <<line;
}

template <typename T , typename T0>
void write(map< T , T0 > &mpp){
    for(auto it : mpp){
        write(it.fst);
        cout << ": ";
        write(it.scd);
        cout << "\n";
    }
    cout<<line;
}
void write(vvll rc,ll n,ll m)
{
    forn(i,n)
    {
        forn(j,m)
        {
            cout<<rc[i][j]<<" ";
        }
        cout<<line;
    }
}
ll maxl(ll a,ll b)
{
    return (a>b)?a:b;
}
ll minl(ll a,ll b)
{
    return (a<b)?a:b;
}
void show(vector<pair<ll,pll>> a,ll n)
{
    forn(i,n)
    {
        cout<<a[i].scd.fst<<" "<<a[i].scd.scd<<" , ";
    }
    cout<<line;
}
void solve()
{
    ll n,q;
    read(n,q);
    string s;
    read(s);
    vector<pair<ll,pll>> f(n),b(n);
    ll ct=0;
    pll p={0,0};
    forn(i,n)
    {
        if(s[i]=='-')
            ct--;
        else
            ct++;
        p.fst=minl(ct,p.fst);
        p.scd=maxl(ct,p.scd);
        f[i]={ct,p};
    }
    p={0,0};
    ct=0;
    forr(i,n)
    {
        if(s[i]=='+')
            ct--;
        else
            ct++;
        p.fst=minl(ct,p.fst);
        p.scd=maxl(ct,p.scd);
        b[i]={ct,p};
    }
    // show(f,n);
    // show(b,n);
    while(q--)
    {
        ll x,y;
        read(x,y);
        x--,y--;
        pair<ll,pll> p1,p2;
        ll ans;
        if(x>0)
            p1=f[x-1];
        if(y<n-1)
            p2=b[y+1];
        // cout<<p1.scd.fst<<" "<<p1.scd.scd<<line;
        // cout<<p2.scd.fst<<" "<<p2.scd.scd<<line;
        if(x>0 and y<n-1)
        {
            ll diff=p2.fst-p1.fst;
            p2.scd.fst-=diff;
            p2.scd.scd-=diff;
            ans=maxl(p1.scd.scd,p2.scd.scd)-minl(p1.scd.fst,p2.scd.fst)+1;
        }
        else if(x>0)
            ans=p1.scd.scd-p1.scd.fst+1;
        else if(y<n-1)
            ans=p2.scd.scd-p2.scd.fst+1;
        else
            ans=1;
        wrtline(ans);
    }
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//*******************************************************//
test
solve();

return 0;
}