#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ pair Compare(const string& s, const string& t) { int h = 0, b = 0; for (int i : Rep(0, 4)) { for (int j : Rep(0, 4)) { if (s[i] == t[j]) { ++(i == j ? h : b); } } } return {h, b}; } void Solve() { constexpr array D{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; static vector U; if (U.empty()) { for (int m : Rep1(1, 12)) { for (int d : Rep1(1, D[m - 1])) { string s; s += char('0' + m / 10); s += char('0' + m % 10); s += char('0' + d / 10); s += char('0' + d % 10); if (Sz(set(ALL(s))) == 4) { U.push_back(s); } } } } static vector P; if (P.empty()) { for (int a : Rep1(0, 2)) { for (int b : Rep1(0, 9)) { for (int c : Rep1(0, 4)) { for (int d : Rep1(0, 9)) { string s; s += char('0' + a); s += char('0' + b); s += char('0' + c); s += char('0' + d); if (Sz(set(ALL(s))) == 4) { P.push_back(s); } } } } } } assert(ranges::is_sorted(U) && ranges::is_sorted(P)); auto Best = [&](const vector& S) -> string { static map, string> memo; if (memo.contains(S)) { return memo[S]; } int mn = INF; string ret; for (const string& p : P) { map, int> occ; for (const string& s : S) { ++occ[Compare(s, p)]; } if (SetMin(mn, ranges::max(occ | views::values))) { ret = p; } } return memo[S] = ret; }; auto S = U; while (Sz(S) > 1) { auto p = Best(S); OUT('?', p); pair res; IN(res); S.erase(remove_if(ALL(S), [&](const string& s) { return Compare(s, p) != res; }), S.end()); } OUT('!', S[0]); } int main() { ios::sync_with_stdio(false); int t; IN(t); while (t--) { Solve(); } } #elif __INCLUDE_LEVEL__ == 1 #include template concept Range = std::ranges::range && !std::convertible_to; template concept Tuple = std::__is_tuple_like::value && !Range; namespace std { istream& operator>>(istream& is, Range auto&& r) { for (auto&& e : r) is >> e; return is; } istream& operator>>(istream& is, Tuple auto&& t) { apply([&](auto&... xs) { (is >> ... >> xs); }, t); return is; } ostream& operator<<(ostream& os, Range auto&& r) { auto sep = ""; for (auto&& e : r) os << exchange(sep, " ") << e; return os; } ostream& operator<<(ostream& os, Tuple auto&& t) { auto sep = ""; apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t); return os; } } // namespace std using namespace std; #define LAMBDA2(x, y, ...) [&](auto&& x, auto&& y) -> decltype(auto) { return __VA_ARGS__; } #define ALL(r) begin(r), end(r) #define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__) #define Rep1(...) [](int l, int r) { return Rep(l, r + 1); }(__VA_ARGS__) #define Sz(r) int(size(r)) #define SetMin(...) LAMBDA2(x, y, y < x && (x = y, 1))(__VA_ARGS__) #define INF (INT_MAX / 2) #define IN(...) cin >> forward_as_tuple(__VA_ARGS__) #define OUT(...) cout << forward_as_tuple(__VA_ARGS__) << '\n' #endif // __INCLUDE_LEVEL__ == 1