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.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Drogon{
    public static void main(String[] args) throws java.lang.Exception {
        InputReader sc = new InputReader(System.in);
        int t=sc.nextInt();
        while (t-->0){
            int n=sc.nextInt();
            int m=sc.nextInt();
            String s=sc.next();

            int r[][]=new int[n][2];
            int r2[][]=new int[n][2];
            int cnt=0;
            int pre[]=new int[n];
            for (int i=0;i<n;i++){
                if (s.charAt(i)=='+')cnt++;
                else cnt--;
                pre[i]=cnt;
                r[i][0]=Math.max(cnt,0);;
                r[i][1]=Math.min(cnt,0);
                if (i>0){
                    r[i][0]=Math.max(r[i-1][0], pre[i]);
                    r[i][1]=Math.min(r[i-1][1], pre[i]);
                }
//                System.out.println(r[i][0]+" "+r[i][1]);
            }

            cnt=0;
            for (int i=n-1;i>=0;i--){
                int c=s.charAt(i)=='+'?1:-1;
                if (s.charAt(i)=='+')cnt++;
                else cnt--;
                r2[i][0]=Math.max(cnt,0);;
                r2[i][1]=Math.min(cnt,0);
                if (i<n-1){
                    r2[i][0]=Math.max(r2[i+1][0]+c, 0);
                    r2[i][1]=Math.min(r2[i+1][1]+c, 0);
                }
//                System.out.println(r2[i][0]+" "+r2[i][1]);
            }

            StringBuilder sb=new StringBuilder();
            for (int i=0;i<m;i++) {
                int l = sc.nextInt()-1;
                int rr = sc.nextInt()-1;
                if (rr+1==n){
                    if (l-1==-1){
                        sb.append(1+"\n");
                    }else {
                        sb.append((Math.abs(r[l-1][0]-r[l-1][1])+1)+"\n");
                    }
                }else {
                    if (l-1==-1){
                        sb.append((Math.abs(r2[rr+1][0]-r2[rr+1][1])+1)+"\n");
                    }else {
                        int max=Math.max(r[l-1][0], r2[rr+1][0]+pre[l-1]);
                        int min=Math.min(r[l-1][1], r2[rr+1][1]+pre[l-1]);
                        max=Math.max(max, 0);
                        min=Math.min(min, 0);
                        sb.append(Math.abs(max-min)+1);
                        sb.append("\n");
                    }
                }
            }
            System.out.print(sb);

        }
    }


    // [min, max)
    public static int getRandomNumber(int min, int max) {
        return (int) ((Math.random() * (max - min)) + min);
    }

    // nodes from 0 to n-1 nodes
    public static ArrayList<Integer>[] getRandomTree(int n){
        ArrayList<Integer> permutation = new ArrayList<>();
        for (int i=0;i<n;i++){
            permutation.add(i);
        }
        Collections.shuffle(permutation);
        int perIndices[]=new int[n];
        for (int i=0;i<n;i++){
            perIndices[permutation.get(i)]=i;
        }
        ArrayList<Integer> adj[]=new ArrayList[n];
        for (int i=0;i<n;i++)adj[i]=new ArrayList<>();
        for (int i=1;i<n;i++){
            int p=getRandomNumber(0, i);
            adj[perIndices[p]].add(perIndices[i]);
            adj[perIndices[i]].add(perIndices[p]);
            System.out.println(perIndices[p]+" "+perIndices[i]);
        }
        return adj;
    }

    public static int[] getRandomPermutation(int l, int r){
        ArrayList<Integer> permutation=new ArrayList<>();
        for (int i=l;i<=r;i++){
            permutation.add(i);
        }
        Collections.shuffle(permutation);
        int n=permutation.size();
        int ans[]=new int[n];
        for (int i=0;i<n;i++){
            ans[i]=permutation.get(i);
        }
        return ans;
    }

    // generate random array with elements in range [l, r)
    static int[] generateRandomArray(int n, int l, int r){
        int arr[]=new int[n];
        for (int i=0;i<n;i++){
            int myRandomInt = getRandomNumber(l, r);
            arr[i]=myRandomInt;
        }
        return arr;
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0) return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9') throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}