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

bool ask(int y) {
  printf("%d\n", y);
  fflush(stdout);
  int r;
  scanf("%d", &r);
  if (r == -1) {
    exit(1);
  }
  return r;
}

void work() {
  int n, k;
  scanf("%d %d", &n, &k);
  bool done = ask(0);
  for (int i = 1; i < n && !done; i++) {
    int y = (i ^ (i - 1));
    done = ask(y);
  }
}

int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  
  int T = 0;
  scanf("%d", &T);
  for (int casen = 1; casen <= T; casen++) {
    work();
  }
  
  return 0;
}