import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Solution {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String[] args){
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        boolean []node = new boolean[300000+5];
        int[] edge = new int[100000+5];
        int q,n,m;
        q = in.nextInt();
        int a,b;
        while(q--!=0){
            n = in.nextInt();m = in.nextInt();
            for(int i=1;i<=3*n;i++){
                node[i] = false;
            }
            int edgeNum = 0;
            for(int i=1;i<=m;i++){
                a = in.nextInt();b = in.nextInt();
                if(!node[a]&&!node[b]){
                    node[a] = true;node[b] = true;
                    edge[edgeNum++] = i;
                }
            }
            if(edgeNum>=n){
                out.println("Matching");
                for(int i=0;i<n;i++){
                    out.print(edge[i]);
                    out.print(" ");
                }
                out.println();
            }else{
                out.println("IndSet");
                for(int i=1,j=0;i<=3*n&&j<n;i++){
                    if(!node[i]){
                        out.print(i);
                        out.print(" ");
                        j++;
                    }
                }
                out.println();
            }
        }

        out.close();
    }
}