#include #include #include #include #include #include #include #include #include using namespace std; const int maxn = 1000005; int cntx[maxn], cnty[maxn]; int x[maxn], y[maxn]; int n, m, k, seed; 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; } 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; cin >> T; while(T--) { memset(cntx, 0, sizeof(cntx)); memset(cnty, 0, sizeof(cnty)); Init(); int coux = 0, couy = 0; for(int i = 1; i <= k; i++) { int tx = x[i]; int ty = y[i]; if(cntx[tx] == 0) { cntx[tx] = 1; //cou++; } if(cnty[ty] == 0) { cnty[ty] = 1; //cou++; } } for(int i = 1; i <= n; i++) if(cntx[i] == 1) coux++; for(int i = 1; i <= m; i++) if(cnty[i] == 1) couy++; cout << n - coux << " " << m - couy << endl; } return 0; }