#include <bits/stdc++.h>
using namespace std;
struct H {
  int x, y, z;
};
int i, j, k, l, m, n, p, s, t, u, v, pv[300018], w[300018], x[100005];
H d[300018], e[1000005];
int C(H a, H b) { return a.x < b.x; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (cin >> t; t--;) {
    cin >> n >> m;
    v = 3 * n;
    for (i = 0; i++ < v;) {
      d[i].x = w[i] = x[i] = 0;
      d[i].y = i;
    }
    d[i].y = v + 1;
    for (i = 0; i < m; i++) {
      cin >> e[i].x >> e[i].y;
      e[i + m].x = e[i].y;
      e[i + m].y = e[i].x;
      e[i].z = e[i + m].z = i + 1;
      d[e[i].x].x++;
      d[e[i].y].x++;
    }
    m <<= 1;
    sort(e, e + m, C);
    sort(d, d + v + 1, C);
    for (i = 0; ++i < m;) {
      if (e[i].x > e[i - 1].x) {
        for (j = e[i - 1].x; j++ < e[i].x;) {
          pv[j] = i;
        }
      }
    }
    for (j = e[m - 1].x; j++ < v + 1;) pv[j] = m;
    for (i = k = 0; i++ < n && k < n;) {
      for (j = pv[u = d[i].y], l = pv[u + 1], p = 1; j < l; j++) {
        if (w[e[j].y]) p = 0;
      }
      if (p) {
        x[++k] = u;
        w[u] = 1;
      }
    }
    if (k < n) {
      for (i = 0; i++ < v;) w[i] = 0;
      for (i = k = 0; i < m && k < n; i++) {
        if (!w[e[i].x] && !w[e[i].y]) {
          x[++k] = e[i].z;
          w[e[i].x] = w[e[i].y] = 1;
        }
      }
      sort(x, x + n + 1);
      cout << "Matching" << '\n';
    } else {
      sort(x, x + n + 1);
      cout << "IndSet" << '\n';
    }
    for (i = 0; i++ < n;) cout << x[i] << ' ';
    cout << '\n';
  }
}
