#include <bits/stdc++.h>
int main(int argc, char const *argv[]) {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, m;
    scanf("%d%d", &n, &m);
    std::vector<short> vertices(3 * n, 0);
    std::vector<int> edges;
    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (!vertices[u - 1] && !vertices[v - 1]) {
        vertices[u - 1] = 1;
        vertices[v - 1] = 1;
        edges.push_back(i + 1);
      }
    }
    if (edges.size() >= n) {
      printf("Matching\n");
      for (int i = 0; i < n; i++) printf("%d\n", edges[i]);
    } else {
      printf("IndSet\n");
      for (int i = 0, cnt = 0; i < 3 * n && cnt < n; i++) {
        if (!vertices[i]) {
          cnt++;
          printf("%d\n", i + 1);
        }
      }
    }
  }
  return 0;
}
