#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(){ memset(x, 0, sizeof(x)); memset(y, 0, sizeof(y)); scanf("%d%d%d%d",&n,&m,&k,&seed); _X=seed; for (int i=1;i<=k;++i){ int s1 = get_rand(1,n), s2 = get_rand(1,m); x[s1]++, y[s2]++; } int cnt_x = 0, cnt_y = 0; for(int i = 1; i <= n; i++) if(x[i]) cnt_x++; for(int i = 1; i <= m; i++) if(y[i]) cnt_y++; printf("%d %d\n",n-cnt_x, m-cnt_y); } int main() { int T; scanf("%d", &T); while(T--){ Init(); } return 0; }