#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
#include <cstdlib>
#include<stdlib.h>
#include<sstream>
#include<stack>
#include <climits>
#include<vector>
using namespace std;
const int N = 6e6;
vector<int> a[N];
long long t, n, m, x, y;
int main()
{
scanf_s("%llu",&t);
for (long long i = 1; i <=t; i++)
{
scanf_s("%llu %llu", &n, &m);
for (long long j = 1; j <= m; j++)
{
scanf_s("%llu %llu", &x, &y);
a[x].push_back(y);
}
for (long long j = 1; j <= n; j++)
{
for (long long k = a[j].size()-1; k>=0; k--)
{
cout << a[j][k]<<" ";
}
cout << "\n";
}
for (long long j = 1; j <= n; j++)
{
a[j].clear();
}
}
return 0;
}