#include <stdio.h>
#include <stack>
#include <map>
#include <string.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <functional>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
//#define ld long double
const double sn = 1e-6 ;
const int siz = 100005 ;
bool cmp( int a, int b) {
return a > b;
}
int n, m;
int perm[ siz] , root[ siz] , lazy[ siz* 4 ] ;
vector< int > adj[ siz] ;
int tree[ siz* 4 ] ;
set< int , bool ( * ) ( int , int ) > se( cmp) ;
void build( int id, int s, int e) {
if ( s == e) {
tree[ id] = root[ s] ;
if ( root[ s] == 0 ) {
tree[ id] = INT_MAX ;
se.insert ( s) ;
}
return ;
}
int mid = ( s + e) / 2 ;
int le = id * 2 , ri = id * 2 + 1 ;
build( le, s, mid) ;
build( ri, mid+ 1 , e) ;
tree[ id] = min( tree[ le] , tree[ ri] ) ;
}
void fin( int id, int s, int e) {
tree[ id] - = lazy[ id] ;
if ( s ! = e) {
lazy[ 2 * id] + = lazy[ id] ;
lazy[ 2 * id + 1 ] + = lazy[ id] ;
}
lazy[ id] = 0 ;
}
void update( int id, int s, int e, int l, int r) {
if ( lazy[ id] ! = 0 ) {
fin( id, s, e) ;
}
if ( s > r || e < l)
return ;
int le = id * 2 , ri = id * 2 + 1 ;
if ( s >= l && e <= r) {
tree[ id] -- ;
if ( s ! = e) {
lazy[ le] ++ ;
lazy[ ri] ++ ;
}
if ( tree[ id] ! = 0 )
return ;
if ( tree[ id] == 0 && s == e) {
se.insert ( s) ;
tree[ id] = INT_MAX ;
return ;
}
lazy[ le] -- ;
lazy[ ri] -- ;
}
int mid = ( s + e) / 2 ;
update( le, s, mid, l, r) ;
update( ri, mid+ 1 , e, l, r) ;
int bef = tree[ id] ;
tree[ id] = min( tree[ le] , tree[ ri] ) ;
}
int ans[ siz] ;
int main( ) {
int t;
scanf ( "%d" , & t) ;
for ( int ii = 0 ; ii < t; ii++ ) {
scanf ( "%d%d" , & n, & m) ;
for ( int i = 1 ; i <= n; i++ ) {
root[ i] = i - 1 ;
adj[ i] .clear ( ) ;
}
for ( int i = 0 ; i < m; i++ ) {
int a, b;
scanf ( "%d%d" , & a, & b) ;
adj[ a] .push_back ( b) ;
root[ b] -- ;
}
build( 1 , 1 , n) ;
int c = 0 ;
while ( ! se.empty ( ) ) {
int v = * se.begin ( ) ;
ans[ c++ ] = v;
se.erase ( se.begin ( ) ) ;
sort( adj[ v] .begin ( ) , adj[ v] .end ( ) ) ;
int in = v + 1 , sz= adj[ v] .size ( ) ;
for ( int i = 0 ; i < sz; i++ ) {
int en = adj[ v] [ i] - 1 ;
if ( en >= in) {
update( 1 ,1 ,n,in,en) ;
}
in = adj[ v] [ i] + 1 ;
}
if ( in <= n) {
update( 1 , 1 , n, in, n) ;
}
}
for ( int i = 0 ; i < n; i++ ) {
printf ( "%d" , ans[ i] ) ;
if ( i ! = n - 1 )
printf ( " " ) ;
else
printf ( "\n " ) ;
}
}
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8bWF0aC5oPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIHBiIHB1c2hfYmFjawovLyNkZWZpbmUgbGQgbG9uZyBkb3VibGUKY29uc3QgZG91YmxlIHNuID0gMWUtNjsKY29uc3QgaW50IHNpeiA9IDEwMDAwNTsKYm9vbC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