#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<bool> matched(3 * n + 1, false);
  vector<int> M;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (!matched[u] && !matched[v])
      M.emplace_back(i), matched[u] = matched[v] = true;
  }
  if ((int)M.size() >= n) {
    printf("Matching\n");
    for (int i = 0; i < n; ++i) printf("%d\n", M[i]);
  } else {
    printf("IndSet\n");
    for (int i = 1, cnt = 0; i <= 3 * n && cnt < n; ++i) {
      if (!matched[i]) {
        printf("%d\n", i);
        ++cnt;
      }
    }
  }
}
int main() {
  int tt;
  scanf("%d", &tt);
  while (tt--) solve();
  return 0;
}
