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

#define ll long long
#define debug(x) cout<<x<<"DE\n";
#define debug2(x,y) cout<<x<<" "<<y<<"DE\n";
#define _ ios_base::sync_with_stdio(false);
#define mod 1000000007



int main()
{_
    ll t=1,ca=1;
    cin>>t;
    while(t--){
        ll n,k;
        cin>>n>>k;
        for(int i=0;i<n;i++){
            ll z;
            if(i==0)z=i;
            else z=i^(i-1);
            cout<<z<<endl;
            cout.flush();
            ll r;
            cin>>r;
            if(r)break;
        }
    }
}
