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. 
import java.util.*;import java.io.*;import java.math.*;
public class Program
{
    static final Random random=new Random();
    
    static void ruffleSort(int[] a) {
        int n = a.length; 
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n), temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        ArrayList<Integer> lst = new ArrayList<>();
        for(int i : a)
            lst.add(i);
        Collections.sort(lst);
        for(int i = 0; i < n; i++)
            a[i] = lst.get(i);
    }

    static void ruffleSort(long[] a) {
        int n = a.length; 
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        ArrayList<Long> lst = new ArrayList<>();
        for(long i : a)
            lst.add(i);
        Collections.sort(lst);
        for(int i = 0; i < n; i++)
            a[i] = lst.get(i);
    }

    static int[][] st;
 
    public static void process()throws IOException
    {
        int n = ni(), m = ni();
        st = new int[4*n][2];
        char[] ch = nln().toCharArray();
        int c = 0;
        int[] a = new int[n+1];
        for(int i = 1; i <= n; i++){
            if(ch[i-1] == '+')
                c++;
            else
                c--;
            a[i] = c;
        }
        build(a, 1, 1, n+1);
        while(m-- > 0){
            int l = ni(), r = ni();
            int[][] m1 = new int[1][2];
            int[][] m2 = new int[1][2];
            if(l>1){
                m1 = query(1, l, 1, 1, n+1);
            }
            if(r<n){
                m2 = query(r+2, n+1, 1, 1, n+1);
                m2[0][0] -= a[r]-a[l-1];
                m2[0][1] -= a[r]-a[l-1];
            }
            int max = Math.max(m1[0][1], m2[0][1]);
            int min = Math.min(m2[0][0], m1[0][0]);
            pn(max-min+1);
        }
    }

    static void build(int[] a, int v, int l, int r){
        if(l == r){
            st[v][0] = a[l-1];
            st[v][1] = a[l-1];
            return;
        }
        int tm = (l+r)/2;
        build(a, v*2, l, tm);
        build(a, v*2+1, tm+1, r);
        st[v][0] = Math.min(st[v*2][0], st[v*2+1][0]);
        st[v][1] = Math.max(st[v*2][1], st[v*2+1][1]);
    }

    static int[][] query(int left, int right, int v, int l, int r){
        if(l > right || r < left){
            int[][] temp = {{1000000001, -1000000001}};
            return temp;
        }
        if(l >= left && r <= right){
            int[][] temp = {{st[v][0], st[v][1]}};
            return temp;
        }
        int tm = (l+r)/2;
        int[][] ans1 = query(left, right, v*2, l, tm);
        int[][] ans2 = query(left, right, v*2+1, tm+1, r);
        int[][] ans = {{1000000001, -1000000001}};
        ans[0][0] = Math.min(ans1[0][0], ans2[0][0]);
        ans[0][1] = Math.max(ans1[0][1], ans2[0][1]);
        return ans; 
    }
   
    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
        else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
        long s = System.currentTimeMillis();
        int t=1;
        t=ni();
        //int k = t;
        while(t-->0) {/*p("Case #"+ (k-t) + ": ")*/;process();}
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
        out.close();
    }

    static long power(long k, long c, long mod){
        long y = 1;
        while(c > 0){
            if(c%2 == 1)
                y = y * k % mod;
            c = c/2;
            k = k * k % mod;
        }
        return y;
    }

 
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
    static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////
 
    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}