/* Kristoffer Hansen. arnsfelt@daimi.au.dk */ #include #include #include typedef pair point; vector P; int l,w; int best; void update(int a) { if (a>best) best=a; } void split(int i, int y0, int y1) { int px,py; if (y0==y1) return; if (i==P.size()) { update(l*(y1-y0)); } else { px=P[i].first; py=P[i].second; if (y0<=py && py<=y1) { update( px*(y1-y0) ); split(i+1,y0,py); split(i+1,py,y1); } else { split(i+1,y0,y1); } } } void sweep() { int i,j; int y0,y1; int pix,piy; int pjx,pjy; for (i=0; ipiy) y1=pjy; else break; } } if (j==P.size()) update( (l-pix)*(y1-y0) ); } } int main() { int N; int k; int x,y,dx,dy; cin >> N; while (N-->0) { P.clear(); cin >> l >> w; while (cin>>k && k!=0) { cin >> x >> y; if (k==1) P.push_back(point(x,y)); else { cin >> dx >> dy; while (k-->0) { P.push_back(point(x,y)); x+=dx; y+=dy; } } } best=0; sort(P.begin(),P.end()); split(0,0,w); sweep(); cout << best << endl; } return 0; }