#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
	ll a,b,count=2,temp = 3;
	cin>>a>>b;
	vector<long long> pass(a+5);
	pass[0] = 0;pass[1] = 1;pass[2] = 3;pass[3] = 1;
	for(ll i=0;i<a;i++)
	{
		if(i<=3)
		{
			cout<<pass[i]<<endl;
		}
		else
		{
			ll n = i;
			while(!(n&1))
				n/=2;
			if(n==1)
			{
				count*=2;temp+=count;
				cout<<temp<<endl;
				pass[i] = temp;
			}
			else
			{
				pass[i] = pass[i-count];
				cout<<pass[i]<<endl;
			}
		}
		ll ans;
		cin>>ans;
		if(ans==1)	break;
	}
}
int main()
{
	ll t;
	cin>>t;
	while(t--)
        solve();
}
