#include #define mem(a, b) memset(a, b, sizeof(a)) 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; bool vis1[1000005], vis2[1000005]; void Init(){ mem(vis1, 0); mem(vis2, 0); scanf("%d%d%d%d",&n,&m,&k,&seed); int ansn = n, ansm = m; _X=seed; for (int i=1;i<=k;++i) { int a = get_rand(1,n); int b = get_rand(1,m); if(!vis1[a]) vis1[a] = 1, ansn--; if(!vis2[b]) vis2[b] = 1, ansm--; } printf("%d %d\n", ansn, ansm); } int main() { int cas; scanf("%d", &cas); while(cas--) { Init(); } return 0; }