#include #pragma comment(linker, "/STACK:102400000,102400000") #define LL long long #define pii pair #define xx first #define yy second using namespace std; const int N = 510000; vector g[N]; int a[N], r; 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], vx[1000006], vy[1000006]; void Init(){ scanf("%d%d%d%d",&n,&m,&k,&seed); _X=seed; memset (vx, 0, sizeof vx); memset (vy, 0, sizeof vy); for (int i=1;i<=k;++i) { x[i]=get_rand(1,n), y[i]=get_rand(1,m); vx[x[i]] = 1; vy[y[i]] = 1; } int r1 = 0, r2 = 0; for (int i = 1; i <= n; i++) if (!vx[i]) r1++; for (int i = 1; i <= m; i++) if (!vy[i]) r2++; cout << r1 << ' ' << r2 << endl; } int main () { // freopen ("in.txt", "r", stdin); int T; cin >> T; while (T--) { Init (); } }