#include <stdio.h>
#include <string.h>

#define MAXN 10000
#define MAXM 100000

// Graph
int start[MAXN+1];
typedef struct { int from, to; } ARC;
ARC arc[MAXM];
int otherend[MAXM];
int cnt[MAXN];

// Data for 
char visited[MAXN];

void visit(int p)
{
	int i;
	if (visited[p]) return;
	visited[p] = 1;
	for (i = start[p]; i < start[p+1]; i++)
		visit(otherend[i]);
}

int main()
{
	int t, n, m, i, j, k;

	scanf("%d", &t);
	while(t--)
	{
		scanf("%d %d", &n, &m);
		memset(start, 0, sizeof(start));
		for (i=0; i<m; i++)
		{
			scanf("%d %d", &arc[i].to, &arc[i].from);
			arc[i].to--;
			arc[i].from--;
			start[arc[i].from]++;
		}
		for (i=0; i<n; i++) start[i+1] += start[i];
		for (i=0; i<m; i++)
			otherend[--start[arc[i].from]] = arc[i].to;

// Run the searches
		for (i=0; i<n; i++)
		{
			memset(visited, 0, sizeof(visited)); 
			visit(i);
			cnt[i] = 0;
			for (j=0; j<n; j++)
				if (visited[j]) cnt[i]++;
		}

// Count
		m = 0;
		for (i=0; i<n; i++)
			if (cnt[i] > m) m = cnt[i];
// Print the best targets
		for (i=0; i<n; i++)
			if (cnt[i] == m)
				printf("%d ", i+1);
		printf("\n");
	}
	return 0;
}
