#include #include #include #include #include #include using namespace std; const int _K=50268147,_B=6082187,_P=100000007; int _X; inline int get_rand(int _l,int _r){ _X=((long long)_K*_X+_B)%_P; return _X%(_r-_l+1)+_l; } int n,m,k,seed; int x[1000006],y[1000006]; int markx[1000006]; int marky[1000006]; void Init(){ scanf("%d%d%d%d",&n,&m,&k,&seed); _X=seed; for (int i=1;i<=k;++i) { x[i]=get_rand(1,n), y[i]=get_rand(1,m); markx[x[i]]=1; marky[y[i]]=1; } } int t; int main() { scanf("%d",&t); while(t--) { memset(markx,0,sizeof(markx)); memset(marky,0,sizeof(marky)); Init(); int sumn=0,summ=0; for(int i=1;i<=n;i++) { if(markx[i]==0) sumn++; } for(int i=1;i<=m;i++) { if(marky[i]==0) summ++; } printf("%d %d\n",sumn,summ); } return 0; }