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. 
//package credit;


import com.sun.jdi.request.InvalidRequestStateException;

import javax.swing.*;
import javax.swing.text.MutableAttributeSet;
import java.io.*;
import java.net.Inet4Address;
import java.text.CollationElementIterator;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.function.DoublePredicate;

public class sas {
    static boolean v[];
    static int ans[];
    int size[];
    static int count=0;
    static int dsu=0;
    static int c=0;
    int min=Integer.MAX_VALUE;
    int max1=Integer.MIN_VALUE;
    long max=Long.MIN_VALUE;
    boolean aBoolean=true;
    boolean y=false;
        static class FastReader
        {
            BufferedReader br;
            StringTokenizer st;

            public FastReader()
            {
                br = new BufferedReader(new
                        InputStreamReader(System.in));
            }

            String next()
            {
                while (st == null || !st.hasMoreElements())
                {
                    try
                    {
                        st = new StringTokenizer(br.readLine());
                    }
                    catch (IOException  e)
                    {
                        e.printStackTrace();
                    }
                }
                return st.nextToken();
            }

            int nextInt()
            {
                return Integer.parseInt(next());
            }

            long nextLong()
            {
                return Long.parseLong(next());
            }

            double nextDouble()
            {
                return Double.parseDouble(next());
            }

            String nextLine()
            {
                String str = "";
                try
                {
                    str = br.readLine();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
                return str;
            }
        }
        int parent[];
        int rank[];
        ArrayList<ArrayList<Integer>> arrayLists;
        boolean v1[];
        boolean t1=false;
        boolean r=false;
        public static void main(String[] args) throws IOException {
            sas g = new sas();
            g.go();
        }
        public void go() throws IOException {
            FastReader scanner=new FastReader();
//            Scanner scanner=new Scanner(System.in);
            PrintWriter printWriter = new PrintWriter(System.out);
            int t =scanner.nextInt();
            for (int i = 0; i < t; i++) {
                int n=scanner.nextInt();
                int m=scanner.nextInt();
                int p[]=new int[n+1];
                String s=scanner.next();
                int x=0;
                int s1[]=new int[n+1];
                int pmin[]=new int[n+1];
                int pmax[]=new int[n+1];
                int smin[]=new int[n+1];
                int smax[]=new int[n+1];
                int sum=0;
                for (int j =0; j <n; j++) {
                    if(s.charAt(j)=='+'){
                        x++;
                    }else{
                        x--;
                    }
                    p[j+1]=x;
                    pmin[j+1]=Math.min(pmin[j],p[j+1]);
                    pmax[j+1]=Math.max(pmax[j],p[j+1]);
                }
                x=0;
                smin[n]=smax[n]=p[n];
                for (int j =n-1; j>=0; j--) {
                    smin[j]=Math.min(smin[j+1],p[j]);
                    smax[j]=Math.max(smax[j+1],p[j]);
                }
                for (int j = 0; j < m; j++) {
                    int a=scanner.nextInt();
                    int b=scanner.nextInt();
                    long sum1=0;
                    sum1=p[b]-p[a-1];
//                    printWriter.println(smin[n-b]);
                    long imin=Math.min(pmin[a-1],smin[b]-sum1);
                    long imax=Math.max(pmax[a-1],smax[b]-sum1);
                    printWriter.println(imax-imin+1);
                }
            }
            printWriter.flush();
        }
        public void parent(int n){
            for (int i = 0; i < n; i++) {
                parent[i]=i;
                rank[i]=1;
                size[i]=1;
            }
        }
        public void union(int i,int j){
            int root1=find(i);
            int root2=find(j);
//            if(root1 != root2) {
//                parent[root2] = root1;
////                sz[a] += sz[b];
//            }
            if(root1==root2){
                return;
            }
            if(rank[root1]>rank[root2]){
                parent[root2]=root1;
                size[root1]+=size[root2];
            }
            else if(rank[root1]<rank[root2]){
                parent[root1]=root2;
                size[root2]+=size[root1];
            }
            else{
                parent[root2]=root1;
                rank[root1]+=1;
                size[root1]+=size[root2];
            }
        }
        public int find(int p){
           if(parent[p]!=p){
               parent[p]=find(parent[p]);
           }
           return parent[p];
//            if(parent[p]==-1){
//                return -1;
//            }
//            else if(parent[p]==p){
//                return p;
//            }
//            else {
//                parent[p]=find(parent[p]);
//                return parent[p];
//            }
        }
        public double dist(double x1,double y1,double x2,double y2){
            double e=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
            double e1=Math.sqrt(e);
            return e1;
        }
        public void make(int p){
            parent[p]=p;
            rank[p]=1;
        }
        Random rand = new Random();
        public void sort(int[] a, int n) {
                for (int i = 0; i < n; i++) {
                   int j = rand.nextInt(i + 1);
                   int tmp = a[i];
                   a[i] = a[j];
                   a[j] = tmp;
                }
                Arrays.sort(a, 0, n);
        }
        public long gcd(long a,long b){
               if(b==0){
                  return a;
               }
               return gcd(b,a%b);
        }
        public void dfs(ArrayList<Integer> arrayLists1){
            for (int i = 0; i < arrayLists1.size(); i++) {
                if(v1[arrayLists1.get(i)]==false){
                    System.out.println(arrayLists1.get(i));
                    v1[arrayLists1.get(i)]=true;
                    count++;
                    dfs(arrayLists.get(arrayLists1.get(i)));
                }
            }
        }
        private void dfs2(ArrayList<Integer>[]arrayList,int j,int count){
            ans[j]=count;
            for(int i:arrayList[j]){
                if(ans[i]==-1){
                    dfs2(arrayList,i,count);
                }
            }
        }
        private void dfs3(ArrayList<Integer>[] arrayList, int j) {
            v[j]=true;
            count++;
            for(int i:arrayList[j]){
                if(v[i]==false) {
                    dfs3(arrayList, i);
                }
            }
        }
        public double fact(double h){
            double sum=1;
            while(h>=1){
                sum=sum*h;
                h--;
            }
            return sum;
        }
        public long primef(double r){
            long c=0;
            while(r%2==0){
                c++;
                r=r/2;
            }
            for (int i = 3; i <=Math.sqrt(r) ;i+=2) {
                while(r%i==0){
                    c++;
                    r=r/3;
                }
            }
            if(r>2){
                c++;
            }
            return c;
        }
        public long divisor(double r){
            long c=0;
            for (int i = 1; i <=Math.sqrt(r); i++) {
                if(r%i==0){
                    if(r/i==i){
                        c++;
                    }
                    else{
                        c+=2;
                    }
                }
            }
            return c;
        }
}

class Pair{
    double x;
    double y;
    double z;
    public Pair(double x,double y){
        this.x=x;
        this.y=y;
    }
}
class Sorting implements Comparator<Pair> {
    public int compare(Pair p1,Pair p2){
        if(p1.x==p2.x){
            return -1*Double.compare(p1.y,p2.y);
        }
        else {
            return Double.compare(p1.x, p2.x);
        }
    }

}
