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

public class Main {
    void solve() {
       int t = ni();
       while(t-->0) {
           int n = ni(), m = ni();
           boolean vis[] = new boolean[3 * n + 1];
           ArrayList<Integer> ans = new ArrayList<>();
           for (int i = 1; i <= m; i++) {
               int u = ni(), v = ni();
               if (!vis[u] && !vis[v] && ans.size() < n) {
                   ans.add(i);
                   vis[u] = true;
                   vis[v] = true;
               }
           }
           if (ans.size() == n) {
               pw.println("Matching");
               for (int u : ans) pw.println(u);
           } else {
               pw.println("IndSet");
               int cc=n;
               for (int i = 1; i <= 3 * n && cc>0; i++) {
                   if (!vis[i]){
                       cc--;
                       pw.println(i);
                   }
               }
           }
       }

    }
    long M = (long) 1e9 + 7;


    // END
    PrintWriter pw;
    StringTokenizer st;
    BufferedReader br;

    void run() throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
    }

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

    String ns() {
        while (st == null || !st.hasMoreElements()) {

            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    String nextLine() throws Exception {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            throw new Exception(e.toString());
        }
        return str;
    }

    int ni() {
        return Integer.parseInt(ns());
    }

    long nl() {
        return Long.parseLong(ns());
    }

    double nd() {
        return Double.parseDouble(ns());
    }


}