#include <bits/stdc++.h>
using namespace std;
const int nmax = 300005;
vector<int> v[nmax];
int cup[nmax], edg[2 * nmax];
int i, j, n, m, t, rel, a, b, nr;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> t;
  for (int cnt = 1; cnt <= t; cnt++) {
    cin >> n >> m;
    nr = 0;
    for (i = 1; i <= 3 * n; i++) {
      cup[i] = 0;
    }
    for (i = 1; i <= m; i++) {
      cin >> a >> b;
      if (cup[a] + cup[b] == 0) {
        cup[a] = 1;
        cup[b] = 1;
        edg[++nr] = i;
      }
    }
    if (nr >= n) {
      cout << "Matching\n";
      for (i = 1; i <= n; i++) cout << edg[i] << ' ';
      cout << '\n';
    } else {
      int cate = 0;
      cout << "IndSet\n";
      for (i = 1; i <= 3 * n; i++)
        if ((!cup[i]) && cate < n) {
          cout << i << ' ';
          cate++;
        }
      cout << '\n';
    }
  }
  return 0;
}
