
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner s = new Scanner(System.in);
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(reader.readLine());
		String[] input;
		StringBuffer strbf = new StringBuffer();
		while(t-->0) {
			input = reader.readLine().split(" ");
			int n = Integer.parseInt(input[0]), m = Integer.parseInt(input[1]);
			int[][] edges = new int[m][2];
			for(int i = 0; i < m; i++) {
				input = reader.readLine().split(" ");
				int v = Integer.parseInt(input[0]) - 1, u = Integer.parseInt(input[1]) - 1;
				edges[i][0] = v;
				edges[i][1] = u;
			}
			int[] ans = new int[n];
			boolean[] visited = new boolean[3 * n];
			int idx = 0;
			boolean done = false;
			for(int i = 0; i < m && !done; i++) {
				int u = edges[i][0], v = edges[i][1];
				if(!visited[u] && !visited[v]) {
					ans[idx++] = i + 1;
					visited[u] = visited[v] = true;
					if(idx == n) {
						strbf.append("Matching" + System.lineSeparator());
						for(int j = 0; j < n; j++) {
							strbf.append(ans[j] + " ");
						}
						strbf.append(System.lineSeparator());
						done = true;
						break;
					}
				}
			}
			int count = n;
			if(!done)
			strbf.append("IndSet" + System.lineSeparator());
			for(int i = 0; i < 3 * n && !done; i++) {
				
				if(!visited[i]) {
					strbf.append((i + 1) + " ");
					count--;
					if(count == 0) {
//						System.out.println("IndSet");
//						System.out.println(strbf.toString());
						strbf.append(System.lineSeparator());
						done = true;
						break;
					}
				}
			}
			if(!done) {
				strbf.append("Impossible");
				strbf.append(System.lineSeparator());
			}
		}
		System.out.println(strbf.toString());

	}

}
