#include #include #include #include #include #include #include #include #include #include #define X first #define Y second #define clr(u,v); memset(u,v,sizeof(u)); using namespace std; typedef long long ll; typedef pair pii; const int maxn = 1e6 + 10; const int INF = 0x3f3f3f3f; 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]; int Hash1[maxn],Hash2[maxn]; void Init() { clr(Hash1,0); clr(Hash2,0); 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); } int main() { int T; scanf("%d", &T); while (T--) { Init(); for (int i = 1; i <= k; i++) { Hash1[x[i]]++; Hash2[y[i]]++; } int ans1=0,ans2=0; for (int i=0;i