#include <algorithm>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define pii pair<int, int>
#define mii map<int, int>
#define pis pair<int, string>
#define vi vector<int>
#define int long long

//#define endl "\n"
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

using namespace std;

const int inf = 1e16;
const int mod = 1e9 + 7;
const int Max = 1e5 + 5;
int pow(int a, int b)
{
    int res = 1;
    while(b > 0) {
        if(b & 1) {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;

        b >>= 1;
    }
    return res;
}
vector<bool> is_prime(Max, true);
void sieve()
{
    is_prime[0] = false;
    is_prime[1] = false;
    for(int i = 2; i * i < Max; i++) {
        if(is_prime[i]) {
            for(int j = i * i; j < Max; j += i) {
                is_prime[j] = false;
            }
        }
    }
}

int32_t main()
{
    IOS;
    int t;
    t = 1;
    cin >> t;
    while(t--) {
        int n,k;
        cin>>n>>k;
        int last=0;
        for(int i=0;i<n;i++){
            int p=last^i;
            cout<<p<<endl;
            cout.flush();
            int r;
            cin>>r;
            if(r==1) break;
            last=i;
        }
    }

    return 0;
}
