#include <bits/stdc++.h>
#define ll unsigned long long
#define MAXSIZE 500010
using namespace std;
ll T,n,m,u,v,t,a[MAXSIZE];
char c[MAXSIZE];
void getNum(ll x){
t=1;
while(x!=0){
if(x/2==0){
cout<<t<<" ";
break;
}
if(x%2==1)
cout<<t<<" ";
t++;
x/=2;
}
return;
}
int main(){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cin>>T;
memset(a,0,sizeof(a));
memset(c,0,sizeof(c));
for(ll i=0;i<T;i++){
cin>>n>>m;
for(ll j=1;j<=m;j++){
cin>>u>>v;
a[u]|=(1ull<<v-1);
}
for(ll j=1;j<=n;j++){
getNum(a[j]);
cout<<endl;
}
}
}