The Orchard Ledger
Old Mabel keeps her orchard's records on a single sheet of squared paper. The orchard is a rectangle of R rows and C columns of plots, drawn one character per plot:
T— a tree stands on this plot;.— the plot is empty.
Rows are numbered 1 to R from top to bottom and columns 1 to C from left to right, so the plot in row r and column c is written (r, c). Nothing lies outside the drawn rectangle.
Through the season the ledger collects a long list of entries, processed in order:
PLANT r c— a tree is planted on plot(r, c). If a tree already stands there, nothing changes.CUT r c— the tree on plot(r, c)is cut down, leaving the plot empty. If the plot is already empty, nothing changes.COUNT r1 c1 r2 c2— a buyer asks how many trees currently stand in the rectangle with opposite corners(r1, c1)and(r2, c2), both corners included. The corners may be given in any order: the rectangle covers every row betweenr1andr2and every column betweenc1andc2, whichever of each pair is smaller.
Answer every COUNT.
Input
The first line contains two integers R and C (1 ≤ R, C ≤ 1000).
Each of the next R lines contains a string of exactly C characters, each T or . — the orchard at the start of the season.
The next line contains an integer q (1 ≤ q ≤ 2·10^5) — the number of ledger entries.
Each of the next q lines contains one entry: PLANT r c, CUT r c (1 ≤ r ≤ R, 1 ≤ c ≤ C) or COUNT r1 c1 r2 c2 (1 ≤ r1, r2 ≤ R, 1 ≤ c1, c2 ≤ C). At least one entry is a COUNT.
Output
For every COUNT entry, print one line with the number of trees in the requested rectangle.
Notes
In the first example the orchard starts as
T..T
.TT.
T...
The whole orchard holds 5 trees. The rectangle with corners (2, 3) and (1, 2) covers rows 1–2 and columns 2–3, which hold the trees at (2, 2) and (2, 3): 2 trees. Planting at (1, 2) adds a tree; planting at (2, 2) changes nothing because a tree already stands there; cutting (3, 4) changes nothing because that plot is empty. The same rectangle now holds 3 trees. After (2, 3) is cut, the left three columns of rows 1–3 hold the trees at (1, 1), (1, 2), (2, 2) and (3, 1): 4 trees.
In the second example the orchard is a single empty plot.