#include #include #include #include using namespace std; int a[1000006],b[1000006]; 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]; void Init(){ memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); 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); } int main(){ // freopen("input","r",stdin); // freopen("output","w",stdout); int T; scanf("%d",&T); while(T--){ Init(); int ans1=n,ans2=m; for(int i=1;i<=k;i++){ if(!a[x[i]]){ ans1--; a[x[i]]=1; } if(!b[y[i]]){ ans2--; b[y[i]]=1; } } printf("%d %d\n",ans1,ans2); } return 0; }