import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author prem_cse
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, FastReader sc, PrintWriter out) {
            int T = sc.nextInt();
            while (T-- > 0) {
                int n = sc.nextInt();
                int m = sc.nextInt();
                int[] edgeReq = new int[n];
                boolean[] vertex = new boolean[3 * n];
                int matchEdge = 0;
                for (int i = 0; i < m; ++i) {
                    int u = sc.nextInt() - 1;
                    int v = sc.nextInt() - 1;
                    if (matchEdge < n) {
                        if (!vertex[u] && !vertex[v]) {
                            vertex[u] = true;
                            vertex[v] = true;
                            edgeReq[matchEdge++] = i + 1;
                        }
                    }
                }

                if (matchEdge == n) {
                    out.println("Matching");
                    for (int x : edgeReq) out.print(x + " ");
                } else {
                    out.println("IndSet");
                    for (int i = 0; i < vertex.length && n > 0; ++i) {
                        if (!vertex[i]) {
                            out.print((i + 1) + " ");
                            --n;
                        }
                    }
                }
                out.println();
            }
        }

    }

    static class FastReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public FastReader(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());
        }

    }
}

