#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; P get_xy(array d, array c) { int x = 0; rep(i, 4) x += c[i] == d[i]; int bd = 0, bc = 0; for (int di : d) bd |= 1 << di; for (int ci : c) bc |= 1 << ci; int y = popcount(0U + (bc & bd)) - x; return {x, y}; } constexpr int D[]{0, 31,29,31,30,31,30,31,31,30,31,30,31}; vector> days; array test; array get_next(vector> &cands) { int fmx = 1001001001; array res{}; for (auto d : days) { int f[5][5]{}; int bd = 0; for (int di : d) bd |= 1 << di; for (auto c : cands) { auto [x, y] = get_xy(d, c); f[x][y]++; } int t = 0; rep(i, 5) rep(j, 5) chmax(t, f[i][j]); if (chmin(fmx, t)) res = d; } return res; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int cnt = 0; for (int m = 1; m <= 12; m++) { for (int d = 1; d <= D[m]; d++) { int seen = 0; seen |= 1 << m / 10 | 1 << m % 10 | 1 << d / 10 | 1 << d % 10; if (popcount(0U + seen) != 4) continue; days.push_back({m / 10, m % 10, d / 10, d % 10}); cnt++; } } // int mx_cnt = 0; // for (auto d : days) { // test = d; // int cnt = 0; // auto cands = days; // while (cands.size() > 1) { // cnt++; // auto d = get_next(cands); // auto xy = get_xy(test, d); // vector> nc; // for (auto c : cands) if (get_xy(c, d) == xy) { // nc.emplace_back(c); // } // swap(cands, nc); // } // chmax(mx_cnt, cnt); // } // cout << mx_cnt << endl; int tt; cin >> tt; auto ask = [](array d) { cout << "? " << d[0] << d[1] << d[2] << d[3] << endl; int x, y; cin >> x >> y; return pair(x, y); }; while (tt--) { auto cands = days; while (cands.size() > 1) { auto d = get_next(cands); auto xy = ask(d); vector> nc; for (auto c : cands) if (get_xy(c, d) == xy) { nc.emplace_back(c); } swap(cands, nc); } auto c = cands[0]; cout << "! " << c[0] << c[1] << c[2] << c[3] << endl; int res; cin >> res; assert(res == 0); } }