#include #include #include #include #include using namespace std; const int N = 1e6+10; int a[N], b[N]; 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() { int n, m, k, seed, x, y; scanf("%d %d %d %d",&n, &m, &k, &seed); _X=seed; memset(a, 0,sizeof(a)); memset(b,0,sizeof(b)); int cnt1=n, cnt2=m; for (int i=1; i<=k; ++i) { x=get_rand(1,n), y=get_rand(1,m); if(!a[x]) a[x]=1, cnt1--; if(!b[y]) b[y]=1, cnt2--; } printf("%d %d\n",cnt1,cnt2); } int main() { int t; scanf("%d", &t); while(t--) { Init(); } return 0; }