#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
int T, a[500006], tot, n, m;
bool vis[300005];
void solve() {
  tot = 0;
  memset(vis, 0, sizeof(vis));
  n = read();
  m = read();
  int x, y;
  for (int i = 1; i <= m; i++) {
    x = read();
    y = read();
    if (vis[x] || vis[y])
      continue;
    else {
      vis[x] = vis[y] = 1;
      a[++tot] = i;
    }
  }
  if (tot >= n) {
    printf("Matching\n");
    for (int i = 1; i <= n; i++) printf("%d%c", a[i], " \n"[i == n]);
  } else {
    printf("IndSet\n");
    int cnt = n;
    for (int i = 1; i <= 3 * n; i++) {
      if (vis[i]) continue;
      printf("%d", i);
      cnt--;
      if (cnt > 0) {
        printf(" ");
      } else {
        printf("\n");
        break;
      }
    }
  }
}
int main() {
  T = read();
  while (T--) solve();
  return 0;
}
