#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 10;
int n, m;
int ans[maxn], ans_cnt;
bool vis[maxn];
void Solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 3 * n; i++) vis[i] = false;
  ans_cnt = 0;
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (vis[u] || vis[v]) continue;
    vis[u] = vis[v] = true;
    ans[++ans_cnt] = i;
  }
  if (ans_cnt >= n) {
    printf("Matching\n");
    for (int i = 1; i <= n; i++) {
      printf("%d ", ans[i]);
    }
    printf("\n");
  } else if (3 * n - 2 * ans_cnt >= n) {
    printf("IndSet\n");
    ans_cnt = 0;
    for (int i = 1; i <= 3 * n; i++) {
      if (ans_cnt >= n) break;
      if (!vis[i]) {
        printf("%d ", i);
        ans_cnt++;
      }
    }
    printf("\n");
  } else {
    printf("Impossible\n");
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    Solve();
  }
  getchar();
  getchar();
  return 0;
}
