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

#define int             long long
#define ld              long double
#define pb              push_back
#define P               pair<int,int>
#define F               first
#define S               second
#define inf             3e18
#define mod             1000000007
#define vi              vector<int>
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int N = 100005;

int32_t main(){

    FIO;
    
    int t; cin>>t; while(t--)
    {
        int i,j,k,n,m,ans = 0,cnt = 0,sum = 0;
        cin>>n>>k;

        cout<<0<<endl;
        int x; cin>>x;
        if(x) continue;
        for(i=1;i<n;i++){
            int cur = i ^ (i-1);

            cout<<cur<<endl;

            int x; cin>>x;

            if(x) break;
        }


    }
    return 0;
}