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

public class MatchingIndep {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int t = scanner.nextInt();
        while(t-->0) {
            int n = scanner.nextInt(), m = scanner.nextInt();
            HashSet<Integer> used = new HashSet<>();
            ArrayList<Integer> list = new ArrayList<>();
            for(int i = 0; i < m; i++) {
                int u = scanner.nextInt(), v = scanner.nextInt();
                if (!used.contains(u) && !used.contains(v)) {
                    used.add(u);
                    used.add(v);
                    list.add(i+1);
                }
            }
            if (list.size() >= n) {
                out.println("Matching");
                int cnt = 0;
                for(int edge: list) {
                    out.print(edge + " ");
                    cnt++;
                    if (cnt == n) break;
                }
                out.println();
            }
            else {
                out.println("IndSet");
                int cnt = 0;
                for(int i = 1; i <= 3 * n; i++) {
                    if (!used.contains(i)) {
                        out.print(i + " ");
                        cnt++;
                    }
                    if (cnt == n) break;
                }
                out.println();
            }
        }     
        out.flush();
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(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 readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
