#include #include #include #include #include using namespace std; typedef long long LL; 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 T, n,m,k,seed; int x[1000006],y[1000006]; bool flagX[1000006], flagY[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); } void Solve() { memset(flagX, 0, sizeof(flagX)); memset(flagY, 0, sizeof(flagY)); for (int i = 1; i <= k; i++) { if (x[i] <= n) flagX[x[i]] = true; if (y[i] <= m) flagY[y[i]] = true; } int cntX = 0, cntY = 0; for (int i = 1; i <= n; i++) if (!flagX[i]) cntX++; for (int i = 1; i <= m; i++) if (!flagY[i]) cntY++; printf("%d %d\n", cntX, cntY); } int main() { scanf("%d", &T); for (int cas = 1; cas <= T; cas++) { Init(); Solve(); } }