#jag2018summerday2j. [jag2018summer_day2_j]AB Sort

[jag2018summer_day2_j]AB Sort

Problem Statement

You have a string s=s0s1...sN1s=s_0s_1...s_{N-1} of length NN consisting of A and B. You have to process QQ queries. Consider the ii-th query ( 1leqileqQ1 \\leq i \\leq Q ). In this query you are given integers lil_i and rir_i. Then, for each xx ( lileqxleqril_i \\leq x \\leq r_i ), sxs_x is changed to the other letter, that is, A becomes B and B becomes A.

After each query, you have to calculate f(f(B ++ ss ++ A)). Here, f(t)f(t) is a function which, given a string tt, returns a non-negative integer. The value of f(t)f(t) is defined as follows:

  • Consider the following step.
    • Step: For all substrings of tt which coincide with BA, replace them with AB. All replacements are done at the same time.
  • f(t)f(t) is the number of steps you need to perform until no substring of tt coincides with BA.

For example, f(f(ABAB)) \= 11, f(f(BBAA)) \= 33, and f(f(AAA)) \= 00.

Constraints

  • 1leqNleq2000001 \\leq N \\leq 200000
  • s=N|s| = N
  • ss consists of A and B.
  • 1leqQleq2000001 \\leq Q \\leq 200000
  • 0leqlileqrileqN10 \\leq l_i \\leq r_i \\leq N-1
  • N,Q,li,riN,Q,l_i,r_i are integers.

Input

Input is given from Standard Input in the following format:

NN ss QQ l1l_1 r1r_1 l2l_2 r2r_2 : lQl_Q rQr_Q

Output

After each query, print the value of f(f(B ++ ss ++ A)), one per line.


Sample Input 1

5
BAABA
2
1 3
0 2

Sample Output 1

6
6

After the first query, the string ss is BBBAA, so print the value of f(f(BBBBAAA)) in the first line. After the second query, the string ss is AAAAA, so print the value of f(f(BAAAAAA)) in the second line.


Sample Input 2

1
A
2
0 0
0 0

Sample Output 2

2
2