#include <bits/stdc++.h>
using namespace std;
struct t{
int t1,t2;
}a[500010];
bool s(t b,t c){
if(b.t1!=c.t1){
return b.t1<c.t1;
}
return b.t2<c.t2;
}
int main(){
int b,c,d,e,f=0,g=0,h=0,i,j,k;
cin>>b;
for(k=1;k<=b;k++){
cin>>c>>d;
for(i=1;i<=d;i++){
cin>>a[i].t1>>a[i].t2;
}
sort(a+1,a+1+d,s);
i=1;
j=1;
while(j<=d){
while(a[j].t1>i){
i++;
cout<<endl;
}
cout<<a[j].t2<<' ';
j++;
}
cout<<endl;
}
return 0;
}
B3613