#include <bits/stdc++.h>
using namespace std;
int N, M;
int edges[500010][2];
bool del[100010 * 3];
int ansls[100010];
int anscnt;
void work() {
  scanf("%d %d", &N, &M);
  int a, b;
  for (int i = 1; i <= M; i++) {
    scanf("%d %d", &a, &b);
    edges[i][0] = a;
    edges[i][1] = b;
  }
  memset(del, 0, sizeof(bool) * (N * 3 + 3));
  anscnt = 0;
  for (int i = 1; i <= M; i++) {
    a = edges[i][0];
    b = edges[i][1];
    if (del[a] || del[b]) continue;
    del[a] = true;
    del[b] = true;
    ansls[anscnt++] = i;
  }
  if (anscnt >= N) {
    printf("Matching\n");
    for (int i = 0; i < N; i++) {
      printf("%d ", ansls[i]);
    }
    printf("\n");
    return;
  } else {
    printf("IndSet\n");
    anscnt = 0;
    for (int i = 1; i <= 3 * N && anscnt < N; i++) {
      if (!del[i]) {
        anscnt++;
        printf("%d ", i);
        ;
      }
    }
    printf("\n");
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    work();
  }
  return 0;
}
