#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[1000001],y[1000001]; int vis[1000001]; 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); } int main() { int t; scanf("%d", &t); while(t--) { Init(); memset(vis, 0, sizeof(vis)); int cnt = 0, i; for(i = 1; i <= k; i++) vis[x[i]] = true; for(i = 1; i <= n; i++) if(!vis[i]) cnt++; printf("%d ", cnt); cnt = 0; memset(vis, 0, sizeof(vis)); for(i = 1; i <= k; i++) vis[y[i]] = true; for(i = 1; i <= m; i++) if(!vis[i]) cnt++; printf("%d\n", cnt); } return 0; }