#include <bits/stdc++.h>
using namespace std;

#ifndef ONLINE_JUDGE 
  #define DD(x) print(x); cerr<<"\n";
  #define DA(x,y) cerr << #x <<"    \n"; print(x,y); cerr<<"\n";
#else
#define DD(x);
#define DA(x,y);
#endif

#define F first
#define S second
typedef long long ll;
const ll mod = 1e9+7, N = 2e6+7, M = 2e6+7, INF = INT_MAX/10;
ll powe    (ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;}
ll hp2     (ll n){ll p = (ll)log2(n);return (ll)pow(2, p);}
ll cntdg   (ll n){string num = to_string(n);return (ll) num.size();}
void print(ll t) {cerr << t;}void print(int t) {cerr << t;}void print(string t) {cerr << t;}void print(char t) {cerr << t;}void print(long double t) {cerr << t;}void print(double t) {cerr << t;}void print(unsigned long long  t) {cerr << t;}void print(ll foo[], int n){cerr<<"[ ";for(int i=0;i<n;i++)cerr<<foo[i]<<" ";cerr<<"]\n";}template <class T, class V> void print(pair <T, V> p);template <class T> void print(vector <T> v);template <class T> void print(set <T> v);template <class T, class V> void print(map <T, V> v);template <class T> void print(multiset <T> v);template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.F); cerr << ","; print(p.S); cerr << "}"; cerr<<"\n"; }template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]"; cerr<<"\n";}template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]"; cerr<<"\n";}template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]"; cerr<<"\n";}template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]"; cerr<<"\n";}priority_queue<ll, vector<ll>, greater<vector<ll>>> pq; 




void solve(ll tt){
// cout<<"Case #"<<tt<<": ";


ll n,k;
cin>>n>>k;

ll num = 0;

for(int i=0;i<n;i++){

  cout<<(num^i)<<"\n";
  num^=num^i;
  cout.flush();
  ll res;
  cin>>res;
  if(res==1)
  return;


}

cout.flush();
}



int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    cin >> t;
    ll tt = 1;
    while(t--){
      DD("START")    
    	solve(tt);
        tt++;  
      DD("END") 
      cout.flush();
    }
    return 0LL;
}
