#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, from;
} e[2000000];
int t, tot, n, m, num1, num2, ans[2000000];
bool ed[2000000];
inline void addedge(int x, int y) {
  e[++tot].from = x;
  e[tot].to = y;
}
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 3 * n; i++) ed[i] = 0;
  tot = 0;
  for (int i = 1; i <= m; i++) scanf("%d%d", &num1, &num2), addedge(num1, num2);
  num1 = num2 = 0;
}
void solve() {
  for (int i = 1; i <= tot; i++) {
    if (!ed[e[i].from] && !ed[e[i].to]) {
      ans[++num1] = i;
      ed[e[i].from] = ed[e[i].to] = 1;
    }
    if (num1 == n) {
      puts("Matching");
      for (int j = 1; j <= n; j++) printf("%d ", ans[j]);
      puts("");
      return;
    }
  }
  puts("IndSet");
  num1 = 0;
  for (int i = 1; i <= 3 * n && num1 < n; i++) {
    if (!ed[i]) printf("%d ", i), num1++;
  }
  puts("");
}
int main(void) {
  scanf("%d", &t);
  while (t--) {
    init();
    solve();
  }
}
