#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define FORP(i,x) for(int i=2;i*i<=x;i++)
#define ff first
#define ss second
#define endl "\n"
#define vi vector<ll>
#define vpl vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.setf(ios::showpoint);
#define test ll t; cin>>t; while(t--)
void solve()
{
    ll n,k;
	    cin>>n>>k;
	    ll x=0,r;
	    FOR(i,0,n)
	    {
	        ll d=i^x;
	        cout<<d<<endl;
	        cout.flush();
	        x=x^d;
	        
	        cin>>r;
	        if(r)
	        return;
	    }
	    
	    return;
}
int main()
{
	fast;
	test
	{
	    solve();
	}
}