#include<bits/stdc++.h>
#include<algorithm>
#define int long long
#define ll long long
// #define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bs binary_search
#define mp make_pair
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define up upper_bound
#define ld long double
#define meme(a,no)  memset(a,no,sizeof(a))
#define all(v)  v.begin(),v.end()
 

using namespace std; 

const int INF=1e18;

const int N=200000+5;

const int mod=1e9+7;

int32_t main(){
  ios;
  int T;
  cin>>T;
  //T=1;
  while(T--){
    int n,k;
    cin>>n>>k;
    int i,j,l;
    int prev=0;
    int flg=0;
    int ans=0;
    for(i=0;i<n;i++){
      int op=prev^i;
      cout<<op<<endl;
      int res;
      cin>>res;
      if(res==1){
        break;
      }
      prev=i;
    }
  }    
}