#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  int p = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') p = -p;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch - '0'), ch = getchar();
  x = x * p;
}
const int maxn = 1e6 + 10;
struct edge {
  int v, nxt;
} e[maxn << 1];
int head[maxn], ecnt = 0;
void add(int u, int v) {
  e[++ecnt] = (edge){v, head[u]}, head[u] = ecnt;
  e[++ecnt] = (edge){u, head[v]}, head[v] = ecnt;
}
int n, m;
int match[maxn], cnt = 0;
int vis[maxn];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m), ecnt = 0;
    for (int i = 1; i <= 3 * n; i++) head[i] = -1, vis[i] = 0;
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      add(u, v);
    }
    cnt = 0;
    for (int u = 1; u <= 3 * n; u++)
      if (!vis[u]) {
        int flag = 0;
        for (int i = head[u]; ~i; i = e[i].nxt) {
          int v = e[i].v;
          if (vis[v]) continue;
          vis[v] = 1;
          match[++cnt] = (i + 1) >> 1;
          flag = 1;
          break;
        }
        if (flag) vis[u] = 1;
      }
    if (cnt >= n) {
      printf("Matching\n");
      for (int i = 1; i <= n; i++) printf("%d ", match[i]);
      printf("\n");
      continue;
    }
    int num = 0;
    for (int i = 1; i <= 3 * n; i++)
      if (!vis[i]) num++;
    if (num >= n) {
      printf("IndSet\n");
      num = 0;
      for (int i = 1; i <= 3 * n && num < n; i++)
        if (!vis[i]) printf("%d ", i), num++;
      printf("\n");
      continue;
    }
    printf("Impossible\n");
  }
}
