#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
const int maxm = 500005;
int n, m, x[maxm], y[maxm], deg[maxn], p[maxn], q[maxn], tim, cnt;
int head[maxn], to[maxm << 1], nxt[maxm << 1], id[maxm << 1], tot;
set<pair<int, int> > s;
bool vis[maxn], ed[maxn];
inline void addedge(int x, int y, int w) {
  to[++tot] = y;
  id[tot] = w;
  nxt[tot] = head[x];
  head[x] = tot;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= 3 * n; i++) head[i] = deg[i] = ed[i] = 0, vis[i] = 1;
    tim = cnt = tot = 0, s.clear();
    for (int i = 1; i <= m; i++)
      scanf("%d%d", &x[i], &y[i]), addedge(x[i], y[i], i),
          addedge(y[i], x[i], i), deg[x[i]]++, deg[y[i]]++;
    for (int i = 1; i <= 3 * n; i++) s.insert(pair<int, int>(deg[i], i));
    while (!s.empty() && tim < n && cnt < n) {
      int u = s.begin()->second;
      s.erase(s.begin());
      if (vis[u]) q[++cnt] = u;
      if (deg[u] == 0) continue;
      int mx = 0;
      for (int i = head[u], v = to[i]; i; i = nxt[i], v = to[i]) {
        if (vis[u]) vis[v] = 0;
        if (ed[v]) continue;
        if (!mx || deg[v] < deg[to[mx]]) mx = i;
      }
      if (mx) p[++tim] = id[mx], ed[u] = ed[to[mx]] = 1;
      for (int i = head[u], v = to[i]; i; i = nxt[i], v = to[i])
        if (i == mx)
          s.erase(pair<int, int>(deg[v], v));
        else
          s.erase(pair<int, int>(deg[v], v)), deg[v]--,
              s.insert(pair<int, int>(deg[v], v));
    }
    if (tim == n) {
      printf("Matching\n");
      for (int i = 1; i <= n; i++) printf("%d ", p[i]);
      putchar('\n');
      continue;
    }
    if (cnt == n) {
      printf("Indset\n");
      for (int i = 1; i <= n; i++) printf("%d ", q[i]);
      putchar('\n');
      continue;
    }
    printf("Impossible\n");
  }
  return 0;
}
