#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[1000006],y[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); } const int maxn = 1e6 + 10; int v1[maxn], v2[maxn], T; int main() { cin >> T; while(T--) { Init(); memset(v1, 0, sizeof(v1)); memset(v2, 0, sizeof(v2)); for (int i = 1; i <= k; ++ i) { v1[x[i]] = 1; v2[y[i]] = 1; } int x1 = 0, y1 = 0; for (int i = 1; i <= n; ++ i) if(!v1[i]) x1++; for (int j = 1; j <= m; ++ j) if(!v2[j]) y1++; cout << x1 << " " << y1 << endl; } return 0; }