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

public class TaskE {

    void run() {
        FastReader in = new FastReader(System.in);
//        FastReader in = new FastReader(new FileInputStream("input.txt"));
        PrintWriter out = new PrintWriter(System.out);
//        PrintWriter out = new PrintWriter(new FileOutputStream("output.txt"));


        int T = in.nextInt();
        while (T-- > 0) {
            int n = in.nextInt();
            int m = in.nextInt();

            boolean[] were = new boolean[3 * n + 1];
            List<Integer> matching = new ArrayList<>();

            for (int i = 0; i < m; i++) {
                int v = in.nextInt();
                int u = in.nextInt();

                if (!were[v] && !were[u]) {
                    matching.add(i + 1);
                    were[v] = were[u] = true;
                }
            }

            if (matching.size() >= n) {
                out.println("Matching");

                for (int i = 0; i < n; i++)
                    out.print(matching.get(i) + " ");
                out.println();
            } else {
                out.println("IndSet");

                for (int v = 1, i = 0; v <= 3 * n && i < n; v++) {
                    if (!were[v]) {
                        out.print(v + " ");
                        i++;
                    }
                }
                out.println();
            }
        }




        out.close();
    }

    class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

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

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

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

        String next() {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(nextLine());

            return st.nextToken();
        }

        String nextLine() {
            String x = "";
            try {
                x = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return x;
        }
    }


    public static void main(String[] args) {
        new TaskE().run();
    }
}
