Mr. Denjiro is a science teacher. Today he has just received a specially ordered water tank that will certainly be useful for his innovative experiments on water flow.

<image>
---
Figure 1: The water tank

The size of the tank is 100cm (Width) * 50cm (Height) * 30cm (Depth) (see Figure 1). For the experiments, he fits several partition boards inside of the tank parallel to the sideboards. The width of each board is equal to the depth of the tank, i.e. 30cm. The height of each board is less than that of the tank, i.e. 50 cm, and differs one another. The boards are so thin that he can neglect the thickness in the experiments.

<image>
---
Figure 2: The front view of the tank

The front view of the tank is shown in Figure 2.

There are several faucets above the tank and he turns them on at the beginning of his experiment. The tank is initially empty. Your mission is to write a computer program to simulate water flow in the tank.



Input

The input consists of multiple data sets. D is the number of the data sets.

D
DataSet1
DataSet2
...
DataSetD


The format of each data set (DataSetd , 1 <= d <= D) is as follows.

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


Each line in the data set contains one or two integers.

N is the number of the boards he sets in the tank . Bi and Hi are the x-position (cm) and the height (cm) of the i-th board, where 1 <= i <= N .

Hi s differ from one another. You may assume the following.

> 0 < N < 10 ,
>  0 < B1 < B2 < ... < BN < 100 ,
>  0 < H1 < 50 , 0 < H2 < 50 , ..., 0 < HN < 50.

M is the number of the faucets above the tank . Fj and Aj are the x-position (cm) and the amount of water flow (cm3/second) of the j-th faucet , where 1 <= j <= M .

There is no faucet just above any boards . Namely, none of Fj is equal to Bi .

You may assume the following .

> 0 < M <10 ,
>  0 < F1 < F2 < ... < FM < 100 ,
>  0 < A1 < 100, 0 < A2 < 100, ... 0 < AM < 100.

L is the number of observation time and location. Pk is the x-position (cm) of the k-th observation point. Tk is the k-th observation time in seconds from the beginning.

None of Pk is equal to Bi .

You may assume the following .

> 0 < L < 10 ,
>  0 < P1 < 100, 0 < P2 < 100, ..., 0 < PL < 100 ,
>  0 < T1 < 1000000, 0 < T2 < 1000000, ... , 0 < TL < 1000000.

Output

For each data set, your program should output L lines each containing one real number which represents the height (cm) of the water level specified by the x-position Pk at the time Tk.

Each answer may not have an error greater than 0.001. As long as this condition is satisfied, you may output any number of digits after the decimal point.

After the water tank is filled to the brim, the water level at any Pk is equal to the height of the tank, that is, 50 cm.

Example

Input

2
5
15 40
35 20
50 45
70 30
80 10
3
20 3
60 2
65 2
6
40 4100
25 7500
10 18000
90 7000
25 15000
25 22000
5
15 40
35 20
50 45
70 30
80 10
2
60 4
75 1
3
60 6000
75 6000
85 6000


Output

0.666667
21.4286
36.6667
11.1111
40.0
50.0
30.0
13.3333
13.3333
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


enum Type{
	IN,
	LEFT,
	RIGHT,
	DOUBLE,
};

enum Event{
	Water_full,
	Height_calc,
};

struct Info{
	void set(double arg_left_H,double arg_right_H,double arg_left_X,double arg_right_X,double arg_per_water,double arg_water_height){
		left_H = arg_left_H;
		right_H = arg_right_H;
		left_X = arg_left_X;
		right_X = arg_right_X;
		per_water = arg_per_water;
		water_height = arg_water_height;
	}

	double left_H,right_H,left_X,right_X,per_water,water_height;
	Type type;
};

struct Data{
	Data(double arg_time,double arg_LOC,int arg_id,Event arg_event){
		time = arg_time;
		LOC = arg_LOC;
		id = arg_id;
		event = arg_event;
	}
	bool operator<(const struct Data &arg) const{
		return time > arg.time; //時間の降順(PQ)
	}
	double time,LOC;
	int id;
	Event event;
};

Info info[11],next_info[11];
double in_water[11];

void func(){

	int N;
	scanf("%d",&N);

	for(int i = 0; i <= N; i++){
		info[i].per_water = 0.0;
		info[i].water_height = 0;
		info[i].type = IN;
	}

	double X,height;
	info[0].left_X = 0;
	info[0].left_H = 50.0;

	for(int i = 1; i <= N; i++){
		scanf("%lf %lf",&X,&height);
		info[i-1].right_X = X;
		info[i-1].right_H = height;
		info[i].left_X = X;
		info[i].left_H = height;
	}
	info[N].right_X = 100.0;
	info[N].right_H = 50.0;
	N++;

	int M;
	scanf("%d",&M);

	double water;
	for(int loop = 0; loop < M; loop++){
		scanf("%lf %lf",&X,&water);
		for(int i = 0; i < N; i++){
			if(X > info[i].left_X && X < info[i].right_X){
				info[i].per_water += water;
				break;
			}
		}
	}

	for(int i = 0; i < N; i++)in_water[i] = info[i].per_water;

	int L;
	scanf("%d",&L);

	priority_queue<Data> Q;
	double tmp_time;
	for(int loop = 0; loop < L; loop++){
		scanf("%lf %lf",&X,&tmp_time);
		Q.push(Data(tmp_time,X,loop,Height_calc));
	}

	//最初に満杯になる区間を計算する
	double min_time = DBL_MAX;
	int min_id;
	for(int i = 0; i < N; i++){
		tmp_time = (info[i].right_X-info[i].left_X)*min(info[i].left_H,info[i].right_H)*30.0/info[i].per_water;
		if(tmp_time < min_time){
			min_time = tmp_time;
			min_id = i;
		}
	}

	Q.push(Data(min_time,-1,min_id,Water_full));
	double pre_calc_height_time = 0; //水が満杯になるタイミングのみで計算する
	double add_water,add_height,pre_height,new_per_water;
	int id,count = 0,left_id,right_id,next_info_index;
	int merge_left,merge_right;

	double ans[10];

	while(!Q.empty()){

		if(Q.top().event == Height_calc){

			//どの区間の高さを求めればよいのか調べる
			for(int i = 0; i < N; i++){
				if(Q.top().LOC > info[i].left_X && Q.top().LOC < info[i].right_X){
					id = i;
					break;
				}
			}

			if(info[id].type == IN){ //水位が増える場合

				add_water = in_water[id]*(Q.top().time-pre_calc_height_time);
				add_height = add_water/((info[id].right_X-info[id].left_X)*30.0);

				ans[Q.top().id] = info[id].water_height+add_height;

			}else{ //水位に変化がない場合
				ans[Q.top().id] = info[id].water_height;
			}
			count++;
			if(count == L){
				for(int k = 0; k < L; k++){
					printf("%.10lf\n",ans[k]);
				}
				return;
			}

		}else{ //Q.top().event == Water_full

			//全区間の水の高さを計算
			for(int i = 0; i < N; i++){
				if(info[i].type != IN)continue; //流れ出る区間はSKIP
				add_water = in_water[i]*(Q.top().time-pre_calc_height_time);
				add_height = add_water/((info[i].right_X-info[i].left_X)*30.0);
				info[i].water_height += add_height;
			}
			pre_calc_height_time = Q.top().time;

			id = Q.top().id;
			merge_left = id;
			merge_right = id;
			//左または右と高さが等しくなれば、区間を統合する(★隣接する区間の高さが異なるようにする★)

			//左が満杯でかつ高さが等しい
			if(id > 0 && info[id-1].type != IN && fabs(info[id-1].water_height-info[id].water_height) < EPS){
				merge_left = id-1;
			}

			if(id+1 < N && info[id+1].type != IN && fabs(info[id+1].water_height-info[id].water_height) < EPS){
				merge_right = id+1;
			}

			new_per_water = 0;
			for(int i = merge_left; i <= merge_right; i++){
				new_per_water += info[i].per_water;
			}

			next_info_index = 0;
			//新しい区間集合を作成
			for(int i = 0; i < merge_left; i++){
				next_info[next_info_index++] = info[i];
			}
			next_info[next_info_index].type = DOUBLE; //★★かつて自分に流れ込んでいた水の行先を変更するため★★
			next_info[next_info_index++].set(info[merge_left].left_H,info[merge_right].right_H,info[merge_left].left_X,info[merge_right].right_X,
								new_per_water,info[merge_left].water_height);
			for(int i = merge_right+1; i < N; i++){
				next_info[next_info_index++] = info[i];
			}

			N = next_info_index;
			for(int i = 0; i < N; i++){
				info[i] = next_info[i];
			}

			for(int i = 0; i < N; i++)in_water[i] = 0;

			//水の流れ方の変化を計算する
			for(int i = 0; i < N; i++){
				if(info[i].water_height+EPS < min(info[i].left_H,info[i].right_H)){ //水位が左右の壁の低い方の高さより低い
					info[i].type = IN;
					in_water[i] += info[i].per_water;
					continue;
				}

				//水があふれる場合→水の流入場所を計算する
				id = i;
				left_id = id;

				//左側
				left_id = id;
				pre_height = info[id].water_height;
				while(left_id > 0 && info[left_id-1].water_height < pre_height && info[left_id-1].right_H <= pre_height+EPS){
					left_id--;
					pre_height = info[left_id].water_height;
					if(info[left_id].type == IN)break;
				}

				//右側
				right_id = id;
				pre_height = info[id].water_height;
				while(right_id+1 < N && info[right_id+1].water_height < pre_height && info[right_id+1].left_H <= pre_height+EPS){
					right_id++;
					pre_height = info[right_id].water_height;
					if(info[right_id].type == IN)break;
				}

				if(left_id == id){ //自分より左に、水が流れ込む場所がない

					if(right_id == id){ //右にも流れ込む場所がない→水槽自体が満杯になったということ
						info[i].type = DOUBLE; //仮に両側としておく
					}else{
						info[i].type = RIGHT;
						in_water[right_id] += info[i].per_water;
					}

				}else{ //自分より左に、水が流れ込む場所がある

					if(right_id == id){ //右には流れ込む場所がない
						info[i].type = LEFT;
						in_water[left_id] += info[i].per_water;
					}else{ //右にも流れ込む場所がある
						info[i].type = DOUBLE;
						in_water[left_id] += info[i].per_water/2;
						in_water[right_id] += info[i].per_water/2;
					}
				}
			}

			//次に、最初に満杯になる区間と時刻を計算
			min_time = DBL_MAX;
			for(int i = 0; i < N; i++){
				if(info[i].type != IN)continue;
				tmp_time = (info[i].right_X-info[i].left_X)*(min(info[i].left_H,info[i].right_H)-info[i].water_height)*30.0/in_water[i];
				if(tmp_time < min_time){
					min_time = tmp_time;
					min_id = i;
				}
			}

			Q.push(Data(Q.top().time+min_time,-1,min_id,Water_full));

		}
		Q.pop();
	}
}

int main(){

	int D;
	scanf("%d",&D);

	for(int loop = 0; loop < D; loop++){
		func();
	}

	return 0;
}

