#include <bits/stdc++.h>
using namespace std;
int f[(300010)], p[(300010)][2], pn;
int nxt[(1000010)], be[(300010)], v[(1000010)], en;
void adde(int a, int b, int id) {
  nxt[id] = be[a];
  v[id] = b;
  be[a] = id;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, m;
    scanf("%d%d", &n, &m);
    n *= 3;
    for (int i = 1; i <= n; ++i) {
      be[i] = 0;
    }
    for (int i = 1, a, b; i <= m; ++i) {
      scanf("%d%d", &a, &b);
      adde(a, b, i << 1);
      adde(b, a, i << 1 | 1);
    }
    memset(f, 0, sizeof(int) * (n + 1));
    for (int i = 1; i <= n; ++i) {
      int mat = 0;
      for (int id = be[i]; id; id = nxt[id]) {
        int j = v[id];
        if (f[j] > 0) {
          mat = 1;
          f[i] = f[j] = -id;
          break;
        }
      }
      if (!mat) {
        f[i] = 1;
      }
    }
    vector<int> ind, ed;
    for (int i = 1; i <= n; ++i) {
      if (f[i] == 1) {
        ind.push_back(i);
      }
      int t = -f[i];
      if (t > 0 && v[t] == i) {
        ed.push_back(t / 2);
      }
    }
    n /= 3;
    if (ed.size() >= n) {
      printf("Matching\n");
      for (int i = 0; i < n; ++i) {
        printf("%d%c", ed[i], " \n"[i == n - 1]);
      }
    } else if (ind.size() >= n) {
      printf("IndSet\n");
      for (int i = 0; i < n; ++i) {
        printf("%d%c", ind[i], " \n"[i == n - 1]);
      }
    } else
      printf("Impossible\n");
  }
}
