#include
using namespace std;
const int N=5e5+10;
int t,n,m;
struct node{
int l,r,val,lazy;
}tr[N<<2];
void pushup(int p){
tr[p].val=tr[p<<1].val+tr[p<<1|1].val;
}
void pushdown(int p){
if(tr[p].lazy!=-1){
tr[p<<1].lazy=tr[p<<1|1].lazy=tr[p].lazy;
tr[p<<1].val=tr[p].lazy*(tr[p<<1].r-tr[p<<1].l+1);
tr[p<<1|1].val=tr[p].lazy*(tr[p<<1|1].r-tr[p<<1|1].l+1);
tr[p].lazy=-1;
}
}
void build(int p,int l,int r){
tr[p]={l,r,r-l+1,-1};
if(l==r){
tr[p].val=1;
return ;
}
int mid=(l+r)>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
}
void update(int p,int l,int r,int val){
if(l<=tr[p].l&&tr[p].r<=r){
tr[p].lazy=val;tr[p].val=val*(tr[p].r-tr[p].l+1);
return ;
}
int mid=(tr[p].l+tr[p].r)>>1;
pushdown(p);
if(mid>=l) update(p<<1,l,r,val);
if(mid+1<=r) update(p<<1|1,l,r,val);
pushup(p);
}
int query(int p,int l,int r){
if(l<=tr[p].l&&tr[p].r<=r){
return tr[p].val;
}
int mid=(tr[p].l+tr[p].r)>>1;
int ret=0;
pushdown(p);
if(l<=mid) ret+=query(p<<1,l,r);
if(mid+1<=r) ret+=query(p<<1|1,l,r);
pushup(p);
return ret;
}
int solve1(int x){
int l=x,r=n;
while(l>1;
if(query(1,x,mid)>0) r=mid;
else l=mid+1;
}
return l;
}
int solve2(int x,int nd){
int l=x,r=n;
while(l>1;
if(query(1,x,mid)>=nd) r=mid;
else l=mid+1;
}
return l;
}
int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
build(1,1,n);
// cout<