import java.util.*;
import java.io.*;
public class EdF {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int t = Integer.parseInt(bf.readLine());
 		for(int i = 0;i<t;i++){
//	 		String input1 = bf.readLine().trim();
//	 		String input2 = bf.readLine().trim();
	 		StringTokenizer st = new StringTokenizer(bf.readLine());
	 		int n = Integer.parseInt(st.nextToken());
	 		int m = Integer.parseInt(st.nextToken());
	 		Set<Integer> vertices = new HashSet<Integer>();
	 		Set<Integer> edges = new HashSet<Integer>();
	 		for(int j = 1;j<=3*n;j++){
	 			vertices.add(j);
	 		}
	 		for(int j =0;j<m;j++){
	 			StringTokenizer st1 = new StringTokenizer(bf.readLine());
	 			int v1 = Integer.parseInt(st1.nextToken());
	 			int v2 = Integer.parseInt(st1.nextToken());
	 			if (vertices.contains(v1) && vertices.contains(v2)){
	 				edges.add(j+1);
	 				vertices.remove(v1);
	 				vertices.remove(v2);
	 			}
	 		}
	 		if (edges.size() >=n){
	 			out.println("Matching");
	 			int count = 0;
	 			for(int j : edges){
	 				count++;
	 				out.print(j + " ");
	 				if (count == n)
	 					break;
	 			}
	 			out.println();
	 		}
	 		else{
	 			out.println("IndSet");
	 			int count = 0;
	 			for(int j : vertices){
	 				count++;
	 				out.print(j + " ");
	 				if (count == n)
	 					break;
	 			}
	 			out.println();
	 		}
 		}
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	


