#include <bits/stdc++.h>
using namespace std;
int T, n, m, x, y;
vector<int> ind, mat;
bool vis[300010];
void init() {
  ind.clear();
  mat.clear();
  memset(vis, 0, sizeof(vis));
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    init();
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &x, &y);
      if (!vis[x] && !vis[y]) {
        mat.push_back(i);
        vis[x] = true;
        vis[y] = true;
      }
    }
    for (int i = 1; i <= 3 * n; i++) {
      if (!vis[i]) ind.push_back(i);
    }
    if (ind.size() >= n) {
      printf("IndSet\n");
      for (int i = 0; i < n; i++) {
        printf("%d ", ind[i]);
      }
    } else {
      printf("Matching\n");
      for (int i = 0; i < n; i++) {
        printf("%d ", mat[i]);
      }
    }
    printf("\n");
  }
  getchar();
  getchar();
  return 0;
}
