#include<bits/stdc++.h>

using namespace std;

#define pi 3.1415926536
#define pb push_back
#define F first
#define S second
//#define endl "\n"
#define bs binary_search
#define int long long
#define float double
#define mii map<int,int>
#define mci map<char,int>
#define msi map<string,int>
#define mss map<string,string>
#define mcc map<char,char>
#define mpi map<pair<int,int>,int>
#define vi vector<int>
#define vs vector<string>
#define si set<int>
#define ss set<string>
#define sc set<char>
int const max1= 1e16+5;
int mod = 1e9+7;
int inf = 1e18;

void solve(){
    int n,k;
    cin>>n>>k;
    //int x=2;
    int temp=0;
    cout<<0<<endl;
    cin>>temp;
    if(temp){
        return;
    }
    cout<<1<<endl;
    cin>>temp;
    if(temp){
        return;
    }
    //x=x^1;
    for(int i=2;i<n;i++){
        //cout<<"ans "<<x<<endl;
        int t = i^(i-1);
        cout<<t<<endl;
        cin>>temp;
        if(temp){
            return;
        }
        //x=x^t;
    }
}

int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
//func();
int tc=1;
cin>>tc;
while(tc--){
    solve();
}
}
