#include #include #include using namespace std; const int maxn=1000000,_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 T,n,m,k,seed,x,y,ansx,ansy; bool visx[maxn],visy[maxn]; int main(){ scanf("%d",&T); while(T--){ memset(visx,0,sizeof(visx)); memset(visy,0,sizeof(visy)); scanf("%d%d%d%d",&n,&m,&k,&seed); ansx=n;ansy=m; _X=seed; while(k--){ x=get_rand(1,n); y=get_rand(1,m); if(!visx[x])ansx--; if(!visy[y])ansy--; visx[x]=visy[y]=true; } printf("%d %d\n",ansx,ansy); } return 0; }