/****************************>>>>HEADFILES<<<<****************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /****************************>>>>>DEFINE<<<<<*****************************/ #define fst first #define snd second #define root 1, N, 1 #define lson l, mid, (rt << 1) #define rson mid + 1, r, (rt << 1 | 1) #define __mid__ int mid = (l + r) >> 1 #define PB(a) push_back(a) #define MP(a,b) make_pair(a,b) #define FIN freopen("input.txt","r",stdin) #define FOUT freopen("output.txt","w",stdout) //#pragma comment(linker, "/STACK:1024000000,1024000000") typedef __int64 LL; const int INF = 0x3f3f3f3f; const int MAXN = 50000 + 5; /****************************>>>>SEPARATOR<<<<****************************/ 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]; bool visx[1000006], visy[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); visx[x[i]] = true; visy[y[i]] = true; } } int main() { #ifndef ONLINE_JUDGE // FIN; #endif // ONLINE_JUDGE int _; scanf("%d", &_); while(_--) { memset(visx, false, sizeof(visx)); memset(visy, false, sizeof(visy)); Init(); int ansx = 0, ansy = 0; for(int i = 1; i <= n; i++) if(visx[i] == false) ansx ++; for(int i = 1; i <= m; i++) if(visy[i] == false) ansy ++; printf("%d %d\n", ansx, ansy); } return 0; }