1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Opis: Główny nagłówek
 */
#include<bits/stdc++.h>
#include "dzilib.h"
using namespace std;
using LL=long long;
#define FOR(i,l,r)for(int i=(l);i<=(r);++i)
#define REP(i,n)FOR(i,0,(n)-1)
#define ssize(x)int(x.size())
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

const int C = 18;
const int W = 2e6 + C + 5;

struct Sito {
	vector<bool> is_prime;
	vector<int> small;
	vector<int> big;
	vector<int> divs;

	Sito() {
		is_prime.resize(W+1, true);
		small.resize(W+1, 1);
		big.resize(W+1, 1);
		divs.resize(W+1, 1);

		FOR(i, 2, W) {
			if (is_prime[i]) {
				small[i] = i;
				big[i] = i;
				divs[i] = 2;
				int cnt = 2;
				for (LL j = (LL)i*i; j <= W; j *= i) {
					is_prime[j] = false;
					small[j] = i;
					big[j] = j;
					divs[j] = cnt + 1;
					cnt++;
				}
				for (LL j = (LL)i * i; j <= W; j += i) {
					if (is_prime[j]) {
						is_prime[j] = false;
						small[j] = i;
					}
				}
			}
			else if (divs[i] == 1) {
				if (small[i / small[i]] == small[i]) {
					big[i] = big[i / small[i]] * small[i];
				}
				else {
					big[i] = small[i];
				}
				divs[i] = divs[i / big[i]] * divs[big[i]];
			}
		}
	}
};




int main() {
	cin.tie(0)->sync_with_stdio(0);

	Sito sito;
	array<int, C> jmps = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};


	// int A = 566658, B = 69858;
	// FOR(i, 0, 20) {
	// 	debug(i, sito.divs[A+i]);
	// 	debug(i, sito.divs[B+i]);
	// }

	map<array<int, C>, int> info;
	FOR(i, 1, (int)1e6) {
		array<int, C> new_info;
		REP(j, C) {
			new_info[j] = sito.divs[i + jmps[j]];
		}
		// if (info.find(new_info) != info.end()) {
		// 	cout << i << " " << info[new_info] << endl;
		// 	return 0;
		// }
		info[new_info] = i;
	}

	int t = GetT();
	int n = GetN();
	int q = GetQ();
	int c = GetC();
	while (t--) {
		array<int, C> curr_divs;
		REP(j, C) {
			curr_divs[j] = Ask(j);
		}
		Answer(info[curr_divs]);
	}



	// cout << ssize(info);
	// debug(ssize(info));

}