#include #include #include #include #include #include #include using namespace std; #define mem(x,y) memset(x,y,sizeof(x)) #define inf 10000000 #define debug puts("-----") #define maxn 100000+5 #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 const int NV = 100005; int sum[NV<<2]; void PushUp(int rt) { sum[rt]=sum[rt<<1]+sum[rt<<1|1]; } void build(int l,int r,int rt=1) { if (l == r) { sum[rt]=0; return ; } int m = (l + r) >> 1; build(lson); build(rson); PushUp(rt); } void update(int L,int c,int l,int r,int rt=1) { if (L == l && l == r) { sum[rt] += c; return ; } int m = (l + r) >> 1; if (L <= m) update(L , c , lson); else update(L , c , rson); PushUp(rt); } int query(int L,int R,int l,int r,int rt=1) { if (L <= l && r <= R) return sum[rt]; int m = (l + r) >> 1; int ret = 0; if (L <= m) ret += query(L , R , lson); if (m < R) ret += query(L , R , rson); return ret; } int sum1[NV<<2]; void PushUp1(int rt) { sum1[rt]=sum1[rt<<1]+sum1[rt<<1|1]; } void build1(int l,int r,int rt=1) { if (l == r) { sum1[rt]=0; return ; } int m = (l + r) >> 1; build1(lson); build1(rson); PushUp1(rt); } void update1(int L,int c,int l,int r,int rt=1) { if (L == l && l == r) { sum1[rt] += c; return ; } int m = (l + r) >> 1; if (L <= m) update1(L , c , lson); else update1(L , c , rson); PushUp1(rt); } int query1(int L,int R,int l,int r,int rt=1) { if (L <= l && r <= R) return sum1[rt]; int m = (l + r) >> 1; int ret = 0; if (L <= m) ret += query1(L , R , lson); if (m < R) ret += query1(L , R , rson); return ret; } int signx[NV],signy[NV]; int main() { int t; scanf("%d",&t); while(t--) { int n,m,k,q; scanf("%d%d%d%d",&n,&m,&k,&q); build(0,n); build1(0,m); mem(signx,0); mem(signy,0); for(int i=0;i