#include using namespace std; typedef long long ll; typedef pair pll; typedef pair pii; typedef pair pdd; typedef vector vi; typedef vector vll; typedef vector vd; typedef vector vs; typedef vector vvi; typedef vector vvvi; typedef vector vvll; typedef vector vvvll; typedef vector vpii; typedef vector vvpii; typedef vector vpll; typedef vector vvpll; typedef vector vpdd; typedef vector vvd; #define yn(ans) printf("%s\n", (ans)?"Yes":"No"); #define YN(ans) printf("%s\n", (ans)?"YES":"NO"); template bool chmax(T &a, T b) { if (a >= b) return false; a = b; return true; } template bool chmin(T &a, T b) { if (a <= b) return false; a = b; return true; } #define FOR(i, s, e, t) for ((i) = (s); (i) < (e); (i) += (t)) #define REP(i, e) for (int i = 0; i < (e); ++i) #define REP1(i, s, e) for (int i = (s); i < (e); ++i) #define RREP(i, e) for (int i = (e); i >= 0; --i) #define RREP1(i, e, s) for (int i = (e); i >= (s); --i) #define all(v) v.begin(), v.end() #define pb push_back #define qb pop_back #define pf push_front #define qf pop_front #define maxe max_element #define mine min_element ll inf = 1e18; #define DEBUG printf("%d\n", __LINE__); fflush(stdout); template void print(vector &v, bool withSize = false) { if (withSize) cout << v.size() << endl; REP(i, v.size()) cout << v[i] << " "; cout << endl; } mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count()); int __FAST_IO__ = []() { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); return 0; }(); #define TESTS int t; cin >> t; while (t--) #define TEST int main() { vi d = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; vs start; REP1(i, 1, 13) { REP1(j, 1, d[i] + 1) { string s(4, '0'); s[0] = i / 10 + '0', s[1] = i % 10 + '0', s[2] = j / 10 + '0', s[3] = j % 10 + '0'; string s2 = s; sort(all(s2)); bool ok = true; REP(k, 3) if (s2[k] == s2[k + 1]) ok = false; if (ok) start.pb(s); } } vs choice; REP(i, 10) REP1(j, i + 1, 10) REP1(k, j + 1, 10) REP1(l, k + 1, 10) { string s(4, ' '); s[0] = i + '0', s[1] = j + '0', s[2] = k + '0', s[3] = l + '0'; choice.pb(s); } auto ask = [&](string &s) { cout << "? " << s << endl; int h, b; cin >> h >> b; if (h == -1) exit(0); return pii{h, b}; }; auto check = [&](string &s, string &pat) { pii ret = {0, 0}; REP(i, 4) REP(j, 4) { if (s[i] == pat[j]) { if (i == j) ret.first++; else ret.second++; break; } } return ret; }; TESTS { vs p; string to = "0123"; auto a = ask(to); for (auto &s: start) { if (check(s, to) == a) p.pb(s); } while (p.size() > 1) { int mn = p.size(); string to = ""; for (auto &s: choice) { map m; for (auto &t: p) m[check(t, s)]++; int mx = 0; for (auto &e: m) chmax(mx, e.second); if (chmin(mn, mx)) to = s; } auto b = ask(to); vs p2; for (auto &e: p) if (check(e, to) == b) p2.pb(e); swap(p, p2); } cout << "! " << p[0] << endl; int x; cin >> x; } return 0; }