#include using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a day,q_day; vector day_ll,q_day_ll; pll mp[10000][1300]; void solve(){ vector ans=day_ll,new_ans; while(1> cnt(5,vector(5,0)); for(auto j:ans){ auto [p,q]=mp[i][j]; cnt[p][q]++; } ll mx=-INF; rep(a,5){ rep(b,5){ chmax(mx,cnt[a][b]); } } if(chmin(mn,mx)) query_ll=i; } string query=to_string(query_ll); while(len(query)<4) query="0"+query; cout << "? " << query << '\n'; cout.flush(); ll h,b; cin >> h >> b; assert(h!=-1&&b!=-1); for(auto j:ans){ auto [p,q]=mp[query_ll][j]; if(h==p&&b==q) new_ans.push_back(j); } swap(ans,new_ans); new_ans.clear(); } assert(!ans.empty()); string ans_str=to_string(*ans.begin()); while(len(ans_str)<4) ans_str="0"+ans_str; cout << "! " << ans_str << '\n'; cout.flush(); ll a; cin >> a; assert(a==0); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); vector d={31,29,31,30,31,30,31,31,30,31,30,31}; replr(i,1,13){ replr(j,1,d[i-1]+1){ string x=to_string(i),y=to_string(j); while(len(x)<=1) x="0"+x; while(len(y)<=1) y="0"+y; day.push_back(x+y); day_ll.push_back(stoll(x+y)); } } rep(i,100){ rep(j,100){ string x=to_string(i),y=to_string(j); while(len(x)<=1) x="0"+x; while(len(y)<=1) y="0"+y; set st={x[0],x[1],y[0],y[1]}; if(len(st)==4){ q_day.push_back(x+y); q_day_ll.push_back(stoll(x+y)); } } } for(auto s:q_day){ for(auto t:day){ ll p=0,q=0; rep(i,4){ rep(j,4){ if(s[i]==t[j]){ if(i==j) p++; else q++; } } } mp[stoll(s)][stoll(t)]={p,q}; } } ll t; cin >> t; while(t--){ solve(); } }