#include #include using namespace std; const int TANK_DEPTH=30; const int TANK_HEIGHT=50; const int TANK_WIDTH=100; const int INF=99999; struct tank_t { int lx,lh,rx,rh; int capacity; int water; tank_t(int lxx=0,int lhh=0,int rxx=0,int rhh=0):lx(lxx),lh(lhh),rx(rxx),rh(rhh){ capacity = (rx-lx)*min(lh,rh)*TANK_DEPTH; water = 0; } }; struct faucet_t { int x,a; faucet_t(int xx=0,int aa=0):x(xx),a(aa){} }; void TankUnion(vector& tank,int index,int target) { if(index > target)swap(index,target); tank[index].rx = tank[target].rx; tank[index].rh = tank[target].rh; tank[index].water += tank[target].water; tank[index].capacity = (tank[index].rx-tank[index].lx)*min(tank[index].lh,tank[index].rh)*TANK_DEPTH; tank.erase(tank.begin()+target); } int GetTankIndex(int x,vector& tank) { for(int i = 0 ; i < (int)tank.size() ; i++) if(tank[i].lx <= x && x < tank[i].rx)return i; return -1; } void OverFlow(int index,vector& tank) { while(tank[index].water > tank[index].capacity) { int target=index+1; bool flg = tank[index].lh < tank[index].rh; if(flg)target = index-1; tank[target].water += tank[index].water-tank[index].capacity; tank[index].water = tank[index].capacity; tank.front().water = 0; tank.back().water = 0; if(tank[target].water >= tank[target].capacity) { if((!flg && tank[target].lh < tank[target].rh) || (flg && tank[target].lh > tank[target].rh)) { TankUnion(tank,index,target); index = min(index,target); } else index = target; } } } double Simulate(int x,int t,vector tank,vector faucet) { vector::iterator p; int index; for(p = faucet.begin() ; p != faucet.end() ; p++) { index = GetTankIndex(p->x,tank); tank[index].water += p->a*t; OverFlow(index,tank); } index= GetTankIndex(x,tank); return (double)tank[index].water/((tank[index].rx-tank[index].lx)*TANK_DEPTH); } int main() { int d,n,m,b,h,f,a,l,p,t; cin >> d; while(d--) { cin >> n; vector tank; tank.push_back(tank_t(-INF,TANK_HEIGHT,0,TANK_HEIGHT)); int prev_b=0; int prev_h=TANK_HEIGHT; while(n--) { cin >> b >> h; tank.push_back(tank_t(prev_b,prev_h,b,h)); prev_b = b; prev_h = h; } tank.push_back(tank_t(prev_b,prev_h,TANK_WIDTH,TANK_HEIGHT)); tank.push_back(tank_t(TANK_WIDTH,TANK_HEIGHT,INF,TANK_HEIGHT)); cin >> m; vector faucet; while(m--) { cin >> f >> a; faucet.push_back(faucet_t(f,a)); } cin >> l; while(l--) { cin >> p >> t; cout.setf(ios::fixed); cout.precision(6); cout << Simulate(p,t,tank,faucet) << endl; } } return 0; }