Ruka

No attempts yetTime limit2sMemory limit512 MB

Problem

Stjepan is programming a robot arm that draws on a blackboard with a piece of chalk. The blackboard is a standard coordinate plane: the xx coordinate grows to the right and the yy coordinate grows upwards.

A plan for the arm is an array of exactly NN vectors (x1,y1),(x2,y2),,(xN,yN)(x_1, y_1), (x_2, y_2), \ldots, (x_N, y_N), where every xix_i and every yiy_i is an even integer. The arm executes the plan from the point (1,1)(1, 1) in NN steps. In step ii it moves the chalk in a straight line from the current point (x,y)(x, y) to the point (x+xi,y+yi)(x + x_i, y + y_i). The mark left on the blackboard is a broken line whose segments are the given vectors.

While Stjepan writes and changes the plan, he sometimes wants to know how many times the chalk goes over the coordinate axes. Write a program that simulates the changes to the plan and answers Stjepan's queries.

The plan at each Q command of the second example. The dotted line marks the segment that was changed most recently.

Suppose Stjepan keeps the plan in a text file of NN lines, where line ii holds the vector (xi,yi)(x_i, y_i). The cursor starts on the first line of the file. Your program simulates the following commands.

  • B: the cursor moves to the previous line. If it is already on the first line, nothing happens.
  • F: the cursor moves to the next line. If it is already on the last line, nothing happens.
  • C nx ny: here nxnx and nyny are even integers. The vector on the cursor line is replaced with the vector (nx,ny)(nx, ny).
  • Q: print how many times the broken line drawn by the current plan goes over the coordinate axes. If the broken line passes through the origin, count that as going over the axes twice.

Input

The first line contains the integer NN, the number of vectors in the plan. Line ii of the following NN lines contains two even integers xix_i and yiy_i separated by a single space, the coordinates of the ii-th vector of the initial plan.

The next line contains the integer MM, the number of commands to simulate. Each of the following MM lines contains one command. A command is one of the uppercase letters B, F, Q, or an expression of the form C nx ny with the even integers nxnx and nyny described above.

Output

For each Q command in the input, print its result on a single line. Print the results in the order in which the commands appear in the input.

Constraints

  • 1N1000001 \le N \le 100000
  • 1M1000001 \le M \le 100000
  • For every vector of the initial plan and every new vector given by a C command, xix_i, yiy_i, nxnx, nyny are even and lie between 500-500 and 500500, inclusive.