#include <bits/stdc++.h>
using namespace std;
struct node {
  int u, v;
} s[1000005];
int t, n, m, ans[1000005], cnt;
bool vis[1000005];
int main() {
  scanf("%d", &t);
  while (t--) {
    cnt = 0;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) scanf("%d%d", &s[i].u, &s[i].v);
    bool flag = 0;
    for (int i = 1; i <= m; i++) {
      if (vis[s[i].u] == 0 && vis[s[i].v] == 0) {
        vis[s[i].u] = 1;
        vis[s[i].v] = 1;
        ans[++cnt] = i;
      }
      if (cnt == n) {
        printf("Matching\n");
        for (int j = 1; j < cnt; j++) {
          printf("%d ", ans[j]);
          vis[s[ans[j]].u] = 0;
          vis[s[ans[j]].v] = 0;
        }
        printf("%d\n", ans[cnt]);
        vis[s[ans[cnt]].u] = 0;
        vis[s[ans[cnt]].v] = 0;
        flag = 1;
        break;
      }
    }
    if (!flag) {
      printf("IndSet\n");
      int tot = 0;
      for (int i = 1; i <= 3 * n; i++) {
        if (!vis[i] && tot < n) {
          printf("%d ", i);
          tot++;
          if (tot == n) printf("\n");
        } else
          vis[i] = 0;
      }
    }
  }
}
