#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int maxn = 3e5 + 7;
const int maxm = 1e6 + 100;
int n, m, que[maxm], ql, qr, pre[maxn], tim = 0, _vis[maxn];
int match2[maxn];
struct edge {
  int v, nxt, id;
} e[maxm];
int h[maxn], tot = 0;
int match[maxn], f[maxn], tp[maxn], tic[maxn];
inline int find(int x) { return f[x] == x ? f[x] : f[x] = find(f[x]); }
inline void add(int u, int v, int id) {
  e[++tot] = (edge){v, h[u], id};
  h[u] = tot;
}
inline int lca(int x, int y) {
  for (++tim;; swap(x, y))
    if (x) {
      x = find(x);
      if (tic[x] == tim)
        return x;
      else
        tic[x] = tim, x = pre[match[x]];
    }
}
inline void shrink(int x, int y, int p) {
  while (find(x) != p) {
    pre[x] = y, y = match[x];
    if (tp[y] == 2) tp[y] = 1, que[++qr] = y;
    if (find(x) == x) f[x] = p;
    if (find(y) == y) f[y] = p;
    x = pre[y];
  }
}
inline bool aug(int s) {
  for (int i = 1; i <= n; ++i) f[i] = i;
  for (int i = 1; i <= n; i++) tp[i] = pre[i] = 0;
  tp[que[ql = qr = 1] = s] = 1;
  int t = 0;
  while (ql <= qr) {
    int x = que[ql++];
    for (int i = h[x], v = e[i].v; i; i = e[i].nxt, v = e[i].v) {
      if (find(v) == find(x) || tp[v] == 2) continue;
      if (!tp[v]) {
        tp[v] = 2, pre[v] = x;
        if (!match[v]) {
          for (int now = v, last, tmp; now; now = last) {
            last = match[tmp = pre[now]];
            match[now] = tmp, match[tmp] = now;
            match2[now] = e[i].id;
          }
          return true;
        }
        tp[match[v]] = 1, que[++qr] = match[v];
      } else if (tp[v] == 1) {
        int l = lca(x, v);
        shrink(x, v, l);
        shrink(v, x, l);
      }
    }
  }
  return false;
}
void init() {
  for (int i = 1; i <= n; i++) match[i] = match2[i] = tic[i] = h[i] = 0;
  tot = 0;
}
struct Edge {
  int x, y, id;
};
Edge es[maxm];
int nvis[maxn];
int main() {
  int T;
  T = read();
  while (T--) {
    n = read(), m = read();
    n = n * 3;
    if (m >= 1e5 || n >= 1e5 || m < n) {
      for (int i = 1; i <= n; i++) nvis[i] = 0;
      for (int i = 1; i <= m; ++i) {
        int x = read(), y = read();
        es[i] = Edge{x, y, i};
      }
      int cnt = 0;
      random_shuffle(es + 1, es + 1 + m);
      vector<int> ans;
      for (int i = 1; i <= m; i++) {
        if (!nvis[es[i].x] && !nvis[es[i].y]) {
          nvis[es[i].x] = nvis[es[i].y] = 1;
          ans.push_back(es[i].id);
          cnt++;
        }
        if (cnt == n / 3) break;
      }
      if (cnt == n / 3) {
        printf("Matching\n");
        for (int i = 0; i < n / 3; i++) {
          printf("%d", ans[i]);
          if (i != n / 3 - 1) printf(" ");
        }
      } else {
        printf("IndSet\n");
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
          if (!nvis[i]) {
            cnt++;
            printf("%d", i);
            if (cnt != n / 3) printf(" ");
          }
          if (cnt == n / 3) break;
        }
      }
      printf("\n");
      continue;
    }
    init();
    for (int i = 1; i <= m; ++i) {
      int x = read(), y = read();
      add(x, y, i), add(y, x, i);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      ans += (!match[i] && aug(i));
      if (ans == n / 3) break;
    }
    if (ans == n / 3) {
      printf("Matching\n");
      int cnt = 0;
      for (int i = 1; i <= n; i++) {
        if (!match2[i]) continue;
        cnt++;
        printf("%d", match2[i]);
        if (cnt != n / 3) printf(" ");
      }
    } else {
      printf("IndSet\n");
      int cnt = 0;
      for (int i = 1; i <= n; i++) {
        if (cnt == n / 3) break;
        if (!match[i]) {
          printf("%d", i);
          cnt++;
          if (cnt != n / 3) printf(" ");
        }
      }
    }
    printf("\n");
  }
  return 0;
}
