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

public class E_MatchingVsIndependentSet {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {

        private void solve(InputReader inp, PrintWriter out) {
            int t = inp.nextInt();
            for (int i = 0; i < t; i++) solve2(inp, out);
        }

        private void solve2(InputReader inp, PrintWriter out) {
            int n = inp.nextInt(), m = inp.nextInt();
            ArrayList<Integer>[] graph = new ArrayList[3*n];
            ArrayList<Edge> edges = new ArrayList<>();
            for (int i = 0; i < 3*n; i++) graph[i] = new ArrayList<>();
            for (int i = 1; i <= m; i++) {
                int u = inp.nextInt() - 1, v = inp.nextInt() - 1;
                graph[u].add(v);
                graph[v].add(u);
                edges.add(new Edge(u , v, i));
            }
            HashSet<Integer> set = new HashSet<>();
            ArrayList<Edge> matching = new ArrayList<>();
            for (Edge e: edges) {
                if (!set.contains(e.u) && !set.contains(e.v)) {
                    matching.add(e);
                    set.add(e.u);
                    set.add(e.v);
                }
            }
            if (matching.size() >= n) {
                out.println("Matching");
                for (Edge e: matching) out.print(e.id + " ");
                out.print('\n');
            } else {
                out.println("IndSet");
                for (int i = 0; i < 3*n; i++) {
                    if (!set.contains(i)) out.print((i + 1) + " ");
                }
                out.print('\n');
            }
        }

        class Edge {
            int u, v, id;
            public Edge(int u, int v, int id) {
                this.u = u;
                this.v = v;
                this.id = id;
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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