Water Tank

No attempts yetTime limit1sMemory limit128 MB

Problem

A science teacher is preparing an experiment on water flow and has received a specially made water tank.

The tank measures 100 cm in width, 50 cm in height, and 30 cm in depth. Inside the tank he installs several thin partition boards parallel to the two side walls. Each board spans the full depth of the tank (30 cm) and is thin enough that its thickness can be ignored. Every board is shorter than the tank (its height is below 50 cm), and no two boards have the same height.

Several faucets are mounted above the tank. At the start of the experiment every faucet is turned on, and the tank is initially empty. Water poured into one region rises until it reaches the top of the lower of the two walls (a partition board or a side wall) that bound that region, and at that height it spills over into the neighbouring region. Water leaves the tank only when it overflows a side wall at height 50 cm.

Write a program that simulates the water flow and reports the water level at the requested positions and times.

Input

The input consists of multiple data sets. The first line contains D, the number of data sets.

D
DataSet1
DataSet2
...
DataSetD

Each data set has the following format.

N
B1 H1
B2 H2
...
BN HN
M
F1 A1
F2 A2
...
FM AM
L
P1 T1
P2 T2
...
PL TL

Every value is an integer.

N is the number of partition boards. Bi and Hi are the x-position (cm) and height (cm) of the i-th board. The heights Hi are all different. You may assume:

  • 0 < N < 10,
  • 0 < B1 < B2 < ... < BN < 100,
  • 0 < Hi < 50 for every i.

M is the number of faucets. Fj and Aj are the x-position (cm) and the flow rate (cm³ per second) of the j-th faucet. No faucet sits directly above a board, so no Fj equals any Bi. You may assume:

  • 0 < M < 10,
  • 0 < F1 < F2 < ... < FM < 100,
  • 0 < Aj < 100 for every j.

L is the number of observations. Pk is the x-position (cm) and Tk is the time (seconds after the start) of the k-th observation. No Pk equals any Bi. You may assume:

  • 0 < L < 10,
  • 0 < Pk < 100 for every k,
  • 0 < Tk < 1000000 for every k.

Output

For each data set, output L lines. The k-th line is the height (cm) of the water surface at x-position Pk at time Tk.

Because the answer is checked for an exact match and every input value is an integer, each water level is a rational number; print it exactly:

  • if the level is an integer, print that integer;
  • otherwise print it as an irreducible fraction p/q, where q > 1 and gcd(p, q) = 1.

Once the tank has been filled to the brim, the water level at any position equals the height of the tank, 50 cm.