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

typedef long long int ll;
typedef long double ld;

#define pb push_back 
#define all(v)  v.begin(),v.end()

const ll MOD=1000000007;
const ll N=2*10e5;

void solve(){
    ll n,k;
    cin>>n>>k;
    cout<<0<<endl;
    ll a;
    cin>>a;
    if(a==1)return;
    for(ll i=0;i<n;i++){
        ll a1=i^(i+1);
        cout<<a1<<endl;
        cin>>a;
        if(a==1)return;
    }
}
int main(){
      ios_base::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
      // cout << fixed << setprecision(10);
      //freopen("input.txt","r",stdin);
      //freopen("output.txt","w",stdout);
      
      ll t=1;
      cin>>t;
      while(t--){
            solve();
      }
      return 0;
}
 
 