#include #include #include #include #define N_MAX 1000050 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, t; int x[N_MAX], y[N_MAX]; bool l1[N_MAX],l2[N_MAX]; int main() { scanf("%d",&t); while (t--) { scanf("%d %d %d %d", &n, &m, &k, &seed); _X = seed; for (register int i = 1; i <= k; ++i) { x[i] = get_rand(1, n), y[i] = get_rand(1, m); } int ans1 = 0, ans2 = 0; memset(l1, 0, sizeof l1); memset(l2, 0, sizeof l2); for (register int i = 1; i <= k; i++) l1[x[i]] = l2[y[i]] = true; for (register int i = 1; i <= n; i++) if (!l1[i]) ans1++; for (register int i = 1; i <= m; i++) if (!l2[i]) ans2++; printf("%d %d\n", ans1, ans2); } return 0; }