Binary Land BINLAND

Read problem statements in Hindi, Bengali, Mandarin Chinese, Russian, and Vietnamese as well.

Chefland is a city that always changes. It can be viewed as a grid with a fixed width $N$ (with $N$ columns numbered $1$ through $N$) and changing height. The rows of the grid are numbered with positive integers. Each cell in Chefland has a colour, which is either ‘0’ or ‘1’.

From a cell $(x, y)$, it is possible to move to one of the cells $(x+1, y-1)$, $(x+1, y)$ and $(x+1, y+1)$, but only if the destination cell exists and has the same colour as the origin cell.

In Chefland, rows sometimes appear or disappear. However, a row may only appear at the bottom of the grid or disappear if it was at the top of the grid; whenever that happens, rows are renumbered with positive integers from top to bottom in such a way that the topmost row has number $1$.

Now, Chef received a difficult task ― keeping track of the number of ways to move from the topmost row to the bottommost row. He is asking you to help him answer $Q$ queries. Initially, the grid is empty ― it has $0$ rows. There are three types of queries:

Input

Output

For each path query, print a single line containing one integer ― the number of paths modulo $1,000,000,007$.

Constraints

Subtasks

Subtask #1 (10 points):

Subtask #2 (30 points):

Subtask #3 (60 points): original constraints

Example Input

5 9
add 11101
path 1 2
add 01110
path 3 2
add 00100
path 3 3
add 10110
remove
path 1 2

Example Output

0
1
3
2

Explanation

After the first query, the city is:

11101

There is no way to move from column $1$ to column $2$.

After the third query, the city is:

11101
01110

There is only one way to move from the cell $(1, 3)$ to the cell $(2, 2)$: $(1, 3) \rightarrow (2, 2)$.

After the fifth query, the city is:

11101
01110
00100

There are $3$ ways to move from the cell $(1, 3)$ to the cell $(3, 3)$:

After the eighth query, the city is:

01110
00100
10110

There are $2$ ways to move from the cell $(1, 1)$ to the cell $(3, 2)$: