#SGM0000034. A-hoy, Cướp biển! (Ahoy, Pirates!)

A-hoy, Cướp biển! (Ahoy, Pirates!)

Ahoy, Pirates!

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

A binary string is built from repeated patterns. Support setting a range to 1, setting it to 0, flipping it, and counting ones.

Input

The first line contains MM blocks. For each block, one line gives repetition count TT and the next line gives a binary pattern PP. Concatenate PP repeated TT times for all blocks. Then read QQ and QQ operations c a b.

  • F: set [a,b][a,b] to 1.
  • E: set [a,b][a,b] to 0.
  • I: flip all bits in [a,b][a,b].
  • S: count ones in [a,b][a,b].

Indices are zero-based.

Output

For each S query, print the number of ones on its own line. The PHOJ version omits the original case/query labels.

Subtasks

  • 20 points: expanded length N≤50N\le50, Q≤50Q\le50.
  • 30 points: N≤5000N\le5000, Q≤500Q\le500.
  • 50 points: N≤1 024 000N\le1\,024\,000, M≤100M\le100, each T≤200T\le200, ∣P∣≤50|P|\le50, Q≤1000Q\le1000.

Examples

Input

1
1
00101
7
S 0 4
F 0 1
S 0 2
I 1 3
S 0 4
E 3 4
S 0 4

Output

2
3
3
1

Explanation

The initial string 00101 has 2 ones. After F 0 1 it is 11101, so S 0 2 returns 3. Flipping [1,3][1,3] gives 10011 with 3 ones; clearing [3,4][3,4] leaves 10000, so the final answer is 1.