/*
Author : RAJON BARDHAN
AUST CSE 27th Batch
All my programming success are dedicated to my mom , dad , little sister madhobi , teachers , friends and love TANIA SULTANA RIMY
ALGORITHM : SCC
*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define memo(a,b) memset(a,b,sizeof(a))
#define INF 1e9
#define EPS 1e-8
#define PI 3.14159265358979323846
#define maxi 90000
typedef long long ll ;
typedef unsigned long long ull ;
/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction
int N , M , t , cycle , dt[maxi+10] , ft[maxi+10] , ct[maxi+10] , cycleSize[maxi+10] , outdegree[maxi+10] , dp[maxi+10] , check[maxi+10] ;
bool visit[maxi+10] ;
vector <int> G[maxi+10] , GT[maxi+10] , Q ;
void dfs1(int u)
{
visit[u] = true ;
dt[u] = ++t ;
for(int i=0;i<G[u].size();i++)
{
int v = G[u][i] ;
if(!visit[v]) dfs1(v);
}
ft[u] = ++t ;
Q.pb(u);
}
void dfs2(int u,int cmp)
{
visit[u] = false ;
ct[u] = cycle ;
cycleSize[cycle]++;
for(int i=0;i<GT[u].size();i++)
{
int v = GT[u][i] ;
if(visit[v]&&cmp>ft[v]) dfs2(v,cmp);
}
}
int dfs3(int u,int prev)
{
check[ct[u]] = prev ;
if(dp[ct[u]]!=-1) return dp[ct[u]] ;
dp[ct[u]] = cycleSize[ct[u]] ;
for(int i=0;i<GT[u].size();i++)
{
int v = GT[u][i] ;
if(ct[u]!=ct[v]&&check[ct[v]]!=prev) dp[ct[u]]+=dfs3(v,prev);
}
return dp[ct[u]] ;
}
void Reset()
{
t = 0 ;
cycle = 1 ;
Q.clear();
for(int i=0;i<=maxi;i++)
{
G[i].clear();
GT[i].clear();
cycleSize[i] = 0 ;
outdegree[i] = 0 ;
check[i] = 0 ;
dp[i] = -1 ;
visit[i] = false ;
}
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int T ;
scanf("%d",&T);
while( T-- )
{
Reset();
scanf("%d%d",&N,&M);
while( M-- )
{
int A , B ;
scanf("%d%d",&A,&B);
G[A].pb(B);
GT[B].pb(A);
}
for(int i=1;i<=N;i++) if(!visit[i]) dfs1(i);
for(int i=Q.size()-1;i>=0;i--) if(visit[Q[i]]) { dfs2(Q[i],ft[Q[i]]); cycle++; }
for(int u=1;u<=N;u++)
{
for(int i=0;i<G[u].size();i++)
{
int v = G[u][i] ;
if(ct[u]!=ct[v]) outdegree[ct[u]]++;
}
}
int mx = 0 ;
set < pair<int,int> > S ;
for(int i=1;i<=N;i++)
{
if(outdegree[ct[i]]==0)
{
int t = dfs3(i,i) ;
S.insert(mp(i,t));
mx=max(mx,t);
}
}
bool flag = true ;
for(auto i:S)
{
if(i.ss==mx)
{
if(flag) flag = false ; else printf(" ");
printf("%d",i.ff);
}
}
puts("");
}
return 0;
}
LyoKICAgIEF1dGhvciA6IFJBSk9OIEJBUkRIQU4KICAgIEFVU1QgQ1NFIDI3dGggQmF0Y2gKICAgIEFsbCBteSBwcm9ncmFtbWluZyBzdWNjZXNzIGFyZSBkZWRpY2F0ZWQgdG8gbXkgbW9tICwgZGFkICwgbGl0dGxlIHNpc3RlciBtYWRob2JpICwgdGVhY2hlcnMgLCBmcmllbmRzIGFuZCBsb3ZlIFRBTklBIFNVTFRBTkEgUklNWQoKICAgIEFMR09SSVRITSA6IFNDQwoqLwoKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIGZmIGZpcnN0CiNkZWZpbm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AgICAgICAgY2hlY2tbaV0gPSAwIDsKICAgICAgICBkcFtpXSA9IC0xIDsKICAgICAgICB2aXNpdFtpXSA9ICBmYWxzZSA7CiAgICB9Cn0KaW50IG1haW4oKQp7CiAgICAvL2ZyZW9wZW4oImlucHV0LnR4dCIsInIiLHN0ZGluKTsKICAgIC8vZnJlb3Blbigib3V0cHV0LnR4dCIsInciLHN0ZG91dCk7CiAgICBpbnQgVCA7CiAgICBzY2FuZigiJWQiLCZUKTsKICAgIHdoaWxlKCBULS0gKQogICAgewogICAgICAgIFJlc2V0KCk7CiAgICAgICAgc2NhbmYoIiVkJWQiLCZOLCZNKTsKICAgICAgICB3aGlsZSggTS0tICkKICAgICAgICB7CiAgICAgICAgICAgIGludCBBICwgQiA7CiAgICAgICAgICAgIHNjYW5mKCIlZCVkIiwmQSwmQik7CiAgICAgICAgICAgIEdbQV0ucGIoQik7CiAgICAgICAgICAgIEdUW0JdLnBiKEEpOwogICAgICAgIH0KICAgICAgICBmb3IoaW50IGk9MTtpPD1OO2krKykgaWYoIXZpc2l0W2ldKSBkZnMxKGkpOwogICAgICAgIGZvcihpbnQgaT1RLnNpemUoKS0xO2k+PTA7aS0tKSBpZih2aXNpdFtRW2ldXSkgeyBkZnMyKFFbaV0sZnRbUVtpXV0pOyBjeWNsZSsrOyB9CiAgICAgICAgZm9yKGludCB1PTE7dTw9Tjt1KyspCiAgICAgICAgewogICAgICAgICAgICBmb3IoaW50IGk9MDtpPEdbdV0uc2l6ZSgpO2krKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaW50IHYgPSBHW3VdW2ldIDsKICAgICAgICAgICAgICAgIGlmKGN0W3VdIT1jdFt2XSkgb3V0ZGVncmVlW2N0W3VdXSsrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGludCBteCA9IDAgOwogICAgICAgIHNldCA8IHBhaXI8aW50LGludD4gPiBTIDsKICAgICAgICBmb3IoaW50IGk9MTtpPD1OO2krKykKICAgICAgICB7CiAgICAgICAgICAgIGlmKG91dGRlZ3JlZVtjdFtpXV09PTApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGludCB0ID0gZGZzMyhpLGkpIDsKICAgICAgICAgICAgICAgIFMuaW5zZXJ0KG1wKGksdCkpOwogICAgICAgICAgICAgICAgbXg9bWF4KG14LHQpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGJvb2wgZmxhZyA9IHRydWUgOwogICAgICAgIGZvcihhdXRvIGk6UykKICAgICAgICB7CiAgICAgICAgICAgIGlmKGkuc3M9PW14KQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZihmbGFnKSBmbGFnID0gZmFsc2UgOyBlbHNlIHByaW50ZigiICIpOwogICAgICAgICAgICAgICAgcHJpbnRmKCIlZCIsaS5mZik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcHV0cygiIik7CiAgICB9CiAgICByZXR1cm4gMDsKfQo=