#include<bits/stdc++.h>#define endl '\n'using namespace std;
typedef long long ll;
const int N=500001;
int t;
int n,m,d[N];
set<int> c[N];
inline void work(){
cin >> n >> m;
for (int i=1;i<=n;i++)
c[i].clear();
for (int i=1;i<=m;i++){
int x,y;
cin >> x >> y;
if (c[x].find(y)!=c[x].end())
continue;
c[x].insert(y);
}
for (int i=1;i<=n;i++){
for (auto y:c[i])
cout << y << ' ';
cout << '\n';
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> t;
while (t--) work();
return 0;
}