#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define N 100010
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int rd() {
int res=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f*=-1;ch=getchar();}
while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
return res*f;
}
int T;
int n,m;
struct info {
int l,r;
}A[N];
bool cmp(info x,info y) {
if(x.l^y.l)return x.l<y.l;
return x.r<y.r;
}
priority_queue<int,vector<int>,greater<int> >Q;
int Ans[N];
int main() {
T=rd();
while(T--) {
n=rd(),m=rd();
for(int i=1; i<=m; ++i)A[i].l=rd(),A[i].r=rd();
sort(A+1,A+m+1,cmp);
for(int i=1; i<=n; ++i)Q.push(i);
for(int i=1; i<A[1].l; ++i)Ans[i]=1;
int lx=A[1].l,rx=A[1].l;
for(int i=1; i<=m; ++i) {
while(A[i].l>lx) {
if(Ans[lx])Q.push(Ans[lx]),++lx;
else Ans[lx]=1,++lx;
}
if(rx<lx)rx=lx;
while(rx<=A[i].r)Ans[rx]=Q.top(),Q.pop(),++rx;
}
while(rx<=n)Ans[rx]=1,++rx;
while(!Q.empty())Q.pop();
for(int i=1; i<n; ++i)printf("%d ",Ans[i]);
printf("%d\n",Ans[n]);
for(int i=1; i<=n; ++i)Ans[i]=0;
}
return 0;
}