#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
//#include <windows.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <typeinfo>
#include <vector>

using namespace std;

#define forn(i, n) for (int i = 0; i < n; i++)
#define what_is(x) cerr << '\n' \
                        << #x << " = " << x << '\n'
#define print_arr(heh)    \
    cerr << '\n';         \
    for (auto u : heh)    \
        cerr << u << ' '; \
    cerr << '\n'
#define print_arri(heh)                  \
    cerr << '\n';                        \
    for (int i = 0; i < heh.size(); i++) \
    cerr << #heh << "[" << i << "] = " << heh[i] << '\n'
//#define endl '\n'
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define ld long double
#define DEBUG

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

bool try_ans(int ans) {
    cout << ans << endl;
    bool out;
    cin >> out;
    return out;
}

int flipBits(int n, int k) {
    int mask = (1 << k) - 1;
    return ~n & mask;
}

int count_bits(int n) {
    int cnt = 0;
    while (n > 0) {
        n /= 2;
        cnt++;
    }
    return cnt;
}

void solve() {
    int n, k;
    cin >> n >> k;
    if (try_ans(0)) {
        return;
    }
    for (int i = 1; i < n; i++) {
        int tmp = (i - 1) ^ i;
        if (try_ans(tmp)) {
            return;
        }
    }
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

#ifdef DEBUG
    cerr << "\nTime: " << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

