#include <bits/stdc++.h>
const int maxn = 0x3f3f3f3f;
const double EI =
    2.71828182845904523536028747135266249775724709369995957496696762772407663035354594571382178525166427;
const double PI = 3.141592653589793238462643383279;
using namespace std;
int v[3000010];
int ans[1000010];
int main(void) {
  int t, n, m, i, z1, z2, cnt;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &n, &m);
    cnt = 0;
    memset(v, 0, sizeof(v[0]) * (n * 3 + 5));
    for (i = 0; i < m; i++) {
      scanf("%d %d", &z1, &z2);
      if (!v[z1] && !v[z2]) {
        ans[cnt++] = i + 1;
        v[z1] = 1;
        v[z2] = 1;
      }
    }
    if (cnt >= n) {
      printf("Matching\n");
      for (i = 0; i < n; i++) {
        printf("%d", ans[i]);
        if (i != n - 1) {
          printf(" ");
        }
      }
      printf("\n");
    } else {
      printf("IndSet\n");
      cnt = 0;
      for (i = 1; i <= 3 * n && cnt < n; i++) {
        if (!v[i]) {
          printf("%d", i);
          cnt++;
          if (i != cnt) {
            printf(" ");
          }
        }
      }
      printf("\n");
    }
  }
  return 0;
}
