#include #include #include #include #include using namespace std; bool isLocal = false; string ans_str; int c = 0; pair calc(string s){ c++; assert(ans_str.size()==4); int i,j,h = 0,b = 0; for(i=0;i query(string s){ if(isLocal) return calc(s); cout << "? " << s << endl; int h,b; cin >> h >> b; return {h,b}; } void ans(string s){ if(isLocal){ if(s!=ans_str){ cout << "WA " << s << endl; } assert(s==ans_str); return; } cout << "! " << s << endl; int x; cin >> x; } void solve(){ c = 0; int i,j; pair p = query("0123"); if(p.first + p.second==4){ vector v = {"0213","0312","0321","1023","1203"}; string st = "1230"; if(p.first==4) st = "0123"; for(auto s:v){ auto [h,_] = query(s); if(h==4) st = s; } ans(st); }else if(p.first + p.second==3){ if(p.first==3){ // 0x23 or 012x int h_mn = 4,c_mn = 4,c_mx = 0; char c = '9'; char d; for(i=4;i<9;i++){ string st = "0x23"; string str = st; str[1] = (char)('0' + i); auto [h,b] = query(str); h_mn = min(h_mn,h); c_mn = min(c_mn,h + b); if(c_mx v = {"0x13","0x13","0x13","0x21","0x21"}; vector h,b; for(i=4;i<9;i++){ char d = (char)('0' + i); string s = v[i - 4]; for(j=0;j<4;j++){ if(s[j]=='x') s[j] = d; } auto [_h,_b] = query(s); h.push_back(_h); b.push_back(_b); } if(h[0] + b[0]>h[1] + b[1]) c = '4'; if(h[1] + b[1]>h[0] + b[0]) c = '5'; if(h[2] + b[2]>h[0] + b[0]) c = '6'; if(h[3] + b[3]>h[4] + b[4]) c = '7'; if(h[4] + b[4]>h[3] + b[3]) c = '8'; string s = "032x"; for(i=0;i<5;i++){ int _h = h[i]; if(c - '0' - 4==i) _h--; if(_h>=3) s = v[i]; } for(i=0;i<4;i++){ if(s[i]=='x') s[i] = c; } ans(s); }else if(p.first==1){ char c = '9'; vector v = {"0x12","102x","021x","0x31","031x"}; vector h,b; for(i=4;i<9;i++){ char d = (char)('0' + i); string s = v[i - 4]; for(j=0;j<4;j++){ if(s[j]=='x') s[j] = d; } auto [_h,_b] = query(s); h.push_back(_h); b.push_back(_b); } if(h[0] + b[0]>h[1] + b[1]) c = '4'; if(h[1] + b[1]>h[0] + b[0]) c = '5'; if(h[2] + b[2]>h[0] + b[0]) c = '6'; if(h[3] + b[3]>h[4] + b[4]) c = '7'; if(h[4] + b[4]>h[3] + b[3]) c = '8'; string s; for(i=0;i<5;i++){ int _h = h[i]; if(c - '0' - 4==i) _h--; if(_h>=3) s = v[i]; } for(i=0;i<4;i++){ if(s[i]=='x') s[i] = c; } ans(s); }else{ string s = "1209"; for(i=4;i<9;i++){ string st = "120x"; st[3] = (char)('0' + i); auto [h,_] = query(st); if(h==4) s = st; } ans(s); } }else if(p.first + p.second==2){ auto [h1,b1] = query("0435"); auto [h2,b2] = query("0637"); int c1 = h1 + b1 - 1,c2 = h2 + b2 - 1; int c3 = 2 - c1 - c2; string X = "",Y = ""; if(c1==2) X = "46", Y = "57"; if(c2==2) X = "46", Y = "57"; if(c3==2) X = "48", Y = "59"; if(c1==1 && c2==1) X = "45", Y = "67"; if(c1==1 && c3==1) X = "45", Y = "89"; if(c2==1 && c3==1) X = "67", Y = "89"; string ss = "0x3y"; ss[1] = X[0]; ss[3] = Y[0]; auto [h4,b4] = query(ss); ss[1] = X[0]; ss[3] = Y[1]; auto [h5,b5] = query(ss); int c4 = h4 + b4 - 1,c5 = h5 + b5 - 1; string st = "0x1y"; if(c4==2){ if(h4==3) st[1] = X[0], st[3] = Y[0]; else st[1] = Y[0], st[3] = X[0]; }else if(c5==2){ if(h5==3) st[1] = X[0], st[3] = Y[1]; else st[1] = Y[1], st[3] = X[0]; }else{ if(c4=2) st[1] = X[1], st[3] = Y[1]; else st[1] = Y[1], st[3] = X[1]; }else{ if(h4>=2) st[1] = X[1], st[3] = Y[0]; else st[1] = Y[0], st[3] = X[1]; } } auto [h6,b6] = query(st); if(h6!=4) st[2] = '2'; ans(st); }else{ assert(false); } assert(c<=6); } int main(){ int i,t; cin >> t; while(t){ t--; solve(); } // vector month = {1,2,3,4,5,6,7,8,9,10,11,12}; // vector days = {31,28,31,30,31,30,31,31,30,31,30,31}; // for(i=0;i