#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int INF = 2140000000;
const long long INF2 = 9220000000000000000LL;
const double PI = acos(-1);
const double ERR = 1e-10;
const int N = 1000005;
long long n, m;
bool chk[N];
vector<int> v;
void solve() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  v.clear();
  for (int i = 1; i <= 3 * n; i++) {
    chk[i] = false;
  }
  for (int i = 0; i < m; i++) {
    int o, p;
    scanf("%d %d", &o, &p);
    if (!chk[o] && !chk[p]) {
      v.push_back(i + 1);
      chk[o] = chk[p] = true;
    }
  }
  if (v.size() >= n) {
    printf("Matching\n");
    for (int i = 0; i < n; i++) {
      printf("%d ", v[i]);
    }
  } else {
    printf("IndSet\n");
    int o = 0;
    for (int i = 1; i <= 3 * n; i++) {
      if (!chk[i]) {
        o++;
        printf("%d ", i);
      }
      if (o == n) break;
    }
  }
  printf("\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
