#include using namespace std; #define ll long long #define N 1100000 int T,X,K,V; int f[N],q[N],h,r; int main() { //freopen("tt.in","r",stdin); scanf("%d",&T); while(T--) { scanf("%d%d%d",&X,&K,&V); f[1]=0; q[h=r=1]=1; for(int i=2;i<=X;i++) { while(q[h]f[i])r--; q[++r]=i; } printf("%d\n",f[X]); } return 0; }