#P1473D. Program
Program
Description
You are given a program that consists of instructions. Initially a single variable is assigned to . Afterwards, the instructions are of two types:
- increase by ;
- decrease by .
You are given queries of the following format:
- query — how many distinct values is assigned to if all the instructions between the -th one and the -th one inclusive are ignored and the rest are executed without changing the order?
The first line contains a single integer () — the number of testcases.
Then the description of testcases follows.
The first line of each testcase contains two integers and () — the number of instructions in the program and the number of queries.
The second line of each testcase contains a program — a string of characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
Each of the next lines contains two integers and () — the description of the query.
The sum of over all testcases doesn't exceed . The sum of over all testcases doesn't exceed .
For each testcase print integers — for each query , print the number of distinct values variable is assigned to if all the instructions between the -th one and the -th one inclusive are ignored and the rest are executed without changing the order.
Input
The first line contains a single integer () — the number of testcases.
Then the description of testcases follows.
The first line of each testcase contains two integers and () — the number of instructions in the program and the number of queries.
The second line of each testcase contains a program — a string of characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
Each of the next lines contains two integers and () — the description of the query.
The sum of over all testcases doesn't exceed . The sum of over all testcases doesn't exceed .
Output
For each testcase print integers — for each query , print the number of distinct values variable is assigned to if all the instructions between the -th one and the -th one inclusive are ignored and the rest are executed without changing the order.
Note
The instructions that remain for each query of the first testcase are:
- empty program — was only equal to ;
- "-" — had values and ;
- "---+" — had values , , , , — there are distinct values among them;
- "+--+--+" — the distinct values are , , , .