#include #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 vis_x[maxn], vis_y[maxn]; void solve() { int ax = n, ay = m; memset(vis_x, 0, sizeof(vis_x)); memset(vis_y, 0, sizeof(vis_y)); for (int i = 1; i <= k; i++) { int xx = x[i], yy = y[i]; if (!vis_x[xx]) { vis_x[xx] = 1; ax--; } if (!vis_y[yy]) { vis_y[yy] = 1; ay--; } } printf("%d %d\n", ax, ay); } int main() { int T; scanf("%d", &T); while (T--) { Init(); solve(); } return 0; }