#include "bits/stdc++.h"
using namespace std;
#define int  long long
#define yes "YES\n"
#define no "NO\n"
const int M = 1000000007;

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int T;
    cin >> T;
    //T = 1;
    while(T--){
            int n, k;
            cin >> n >> k;
            int r;
            cout << 0 << endl;
            cin >> r;
            if(r!=1){
                for(int i = 1;i <= n-1;i++){
                    cout << (i^(i-1)) << endl;
                    cin >> r;
                    if(r==1)
                        break;
                }
            }
    }
    return 0;
}


