#include <bits/stdc++.h>
using namespace std;
const int N = 300300;
bool matched[N];
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<int> mcm;
    memset(matched, 0, sizeof matched);
    for (int i = 0; i < m; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      if (matched[u] + matched[v] == 0) {
        mcm.push_back(i + 1);
        matched[u] = matched[v] = 1;
      }
    }
    if (mcm.size() >= n) {
      puts("Matching");
      for (int i = 0; i < n; ++i) printf("%d%c", mcm[i], " \n"[i == n - 1]);
    } else {
      puts("IndSet");
      int cn = 0;
      for (int i = 1; i <= 3 * n; ++i) {
        if (!matched[i]) {
          printf("%d%c", i, " \n"[cn == n - 1]);
          ++cn;
        }
        if (cn == n) break;
      }
    }
  }
  return 0;
}
