#include <bits/stdc++.h>
using namespace std;
int n, m;
int h[300007] = {0};
vector<int> ans;
void work(const int t) {
  scanf("%d%d", &n, &m);
  ans.clear();
  int cnt = 0;
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (h[x] != t && h[y] != t) {
      h[x] = t;
      h[y] = t;
      if (cnt < n) {
        ans.push_back(i);
        cnt++;
      }
    }
  }
  if (cnt == n) {
    puts("Matching");
    for (auto y : ans) {
      printf("%d ", y);
    }
    printf("\n");
    return;
  }
  puts("IndSet");
  for (int i = 1, j = 0; i <= 3 * n && j < n; i++) {
    if (h[i] != t) {
      printf("%d ", i);
      j++;
    }
  }
  printf("\n");
  return;
}
int main() {
  int t;
  memset(h, 0xff, sizeof(h));
  scanf("%d", &t);
  while (t--) {
    work(t);
  }
  return 0;
}
