import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;

public class cf {

	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt(), m = sc.nextInt();
			boolean[] taken = new boolean[3 * n];
			int match = 0;
			Stack<Integer> st = new Stack<>();
			int e = 0;
			while (m-- > 0) {
				e++;
				int u = sc.nextInt() - 1, v = sc.nextInt() - 1;
				if (!taken[u] && !taken[v] && match<n) {
					match++;
					taken[u] = taken[v] = true;
					st.add(e);
				}

			}
			if (match == n) {
				out.println("Matching");
				while (!st.isEmpty()) {
					out.print(st.pop() + " ");
				}
			} else {
				out.println("IndSet");
				for (int i = 0, c = 0; i < 3 * n && c < n; i++) {
					if (!taken[i]) {
						out.print(i + 1 + " ");
						c++;
					}
				}
			}
			out.println();
		}
		out.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreElements())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}

}
