#include <bits/stdc++.h>
using namespace std;
int T;
int N, M;
int did[303030];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &N, &M);
    N *= 3;
    for (i = 0; i < (N); i++) did[i] = 0;
    vector<int> C;
    for (i = 0; i < (M); i++) {
      int U, V;
      scanf("%d%d", &U, &V);
      U--;
      V--;
      if (did[U] == 0 && did[V] == 0) {
        C.push_back(i + 1);
        did[U] = did[V] = 1;
      }
    }
    if (C.size() >= N / 3) {
      (void)printf("Matching\n");
      for (i = 0; i < (N / 3); i++) (void)printf("%d ", C[i]);
      (void)printf("\n");
      continue;
    }
    C.clear();
    for (i = 0; i < (N); i++)
      if (did[i] == 0) C.push_back(i + 1);
    (void)printf("IndSet\n");
    for (i = 0; i < (N / 3); i++) (void)printf("%d ", C[i]);
    (void)printf("\n");
  }
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
