import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class FindRing {
static boolean[][] map;
static boolean[] isT;
static boolean[] isH;
static int[] queue;
static boolean flag;
static int hval;
static int tval;
static int tail;
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
sc = new Scanner(new File("files/findring"));
int T = sc.nextInt();
for (int t = 0; t < T; t++) {
int num = sc.nextInt();
int line = sc.nextInt();
map = new boolean[num + 1][num + 1];
isT = new boolean[num + 1];
isH = new boolean[num + 1];
queue = new int[num + 1];
tail = 0;
flag = false;
for (int i = 0; i < line; i++) {
map[sc.nextInt()][sc.nextInt()] = true;
}
for (int i = 1; i < num + 1; i++) {
if (flag)
break;
if (isT[i])
continue;
dfs(i);
}
if (flag) {
boolean b = false;
for (int i = 0; i < num + 1; i++) {
if (queue[i] == tval)
break;
if (queue[i] == hval)
b = true;
if (b)
System.out.print(queue[i] + " ");
}
System.out.println(tval);
} else
System.out.println("NoRing");
}
}
private static void dfs(int p) {
// TODO Auto-generated method stub
isT[p] = true;
isH[p] = true;
queue[tail++] = p;
for (int i = 1; i < isH.length; i++) {
if (map[p][i]) {
if (isH[i]) {
flag = true;
hval = i;
tval = p;
return;
} else if (!isT[i])
dfs(i);
if (flag)
return;
}
}
isH[p] = false;
tail--;
}
}
sample input:
4
9 10
1 2
2 3
3 4
4 5
6 7
7 4
7 8
8 6
7 9
9 6
5 5
1 2
2 3
4 2
4 5
5 4
6 8
1 2
1 3
2 3
3 4
4 5
5 1
5 2
5 6
4 3
1 2
2 3
3 4
sample output:
6 7 8
4 5
1 2 3 4 5
NoRing