#include #include #include using namespace std; const int maxn = 1e6 + 5; 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,r,c; int x[1000006],y[1000006]; bool used1[maxn], used2[maxn]; void Init(){ scanf("%d%d%d%d",&n,&m,&k,&seed); _X=seed; int x, y; for (int i=1;i<=k;++i) { // x[i]=get_rand(1,n), // y[i]=get_rand(1,m); x = get_rand(1, n); y = get_rand(1, m); if(!used1[x]) { ++r; used1[x] = true; } if(!used2[y]) { ++c; used2[y] = true; } } } int main() { int T; scanf("%d", &T); while(T--) { memset(used1, 0, sizeof(used1)); memset(used2, 0, sizeof(used2)); r = 0, c = 0; Init(); printf("%d %d\n", n - r, m - c); } return 0; }