/*input
 
4
1 2
1 3
1 2
1 2
1 3
1 2
2 5
1 2
3 1
1 4
5 1
1 6
2 15
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6
4 5
4 6
5 6






*/
import java.io.*;
import java.util.*;

 
public class mymy
{
 
	static OutputStream outputStream = System.out;
	static PrintWriter out = new PrintWriter(outputStream);
	static InputStream inputStream = System.in;
	static InputReader br = new InputReader(inputStream);

	static int n;
	

	static int[] vis;	

	

	public static void main(String[] args)throws IOException
	{
		
 		int t=br.nextInt();

 		
 		while(t-->0)
 		{
 			n=br.nextInt()*3;

 			int m=br.nextInt();

 			vis=new int[n];

 			ArrayList<Integer> matching=new ArrayList<Integer>();

 			for(int i=0;i<m;i++)
 			{
 				int l=br.nextInt()-1;
 				int r=br.nextInt()-1;

 				if(vis[l]==0 && vis[r]==0) {matching.add(i+1);vis[l]=1;vis[r]=1;}
 			}

 			int indx=0;
 			n/=3;
 			if(matching.size()>=n)
 			{
 				out.println("Matching");
 				while(n-->0) out.print(matching.get(indx++)+" ");
 				out.println();
 			}
 			else
 			{
 				out.println("IndSet");
 				while(n>0) if(vis[indx++]==0) {out.print(indx+" ");n--;}
 				out.println();
 			}


 		}


 
		out.close();
 
	}





















	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
 
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
 
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
 
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
 
	}
	
}