#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,ans1,ans2; int x[1000006],y[1000006],f1[1000006],f2[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); if(!f1[x[i]]) f1[x[i]]=1,ans1++; if(!f2[y[i]]) f2[y[i]]=1,ans2++; } } void solve() { ans1=ans2=0; memset(f1,0,sizeof(f1)); memset(f2,0,sizeof(f2)); Init(); printf("%d %d\n",n-ans1,m-ans2); } int main() { int T; scanf("%d",&T); while(T--) solve(); }