#include <bits/stdc++.h>
const double PI = acos(-1);
template <class A, class B>
std::ostream& operator<<(std::ostream& st, const std::pair<A, B> p) {
  st << "(" << p.first << ", " << p.second << ")";
  return st;
}
using namespace std;
const int MAXV = 300 * 1000 + 10;
const int MAXE = 500 * 1000 + 10;
int n, m;
int fr[MAXE], to[MAXE];
bool taken[MAXV];
void read() {
  scanf("%d %d", &n, &m);
  for (int e = 1; e <= m; e++) scanf("%d %d", fr + e, to + e);
}
void report(std::vector<int> res, string name) {
  puts(name.c_str());
  for (int i = 0; i < ((int)res.size()); i++)
    printf("%d%c", res[i], " \n"[i == ((int)res.size()) - 1]);
}
void solve() {
  fill(taken, taken + 3 * n + 1, 0);
  std::vector<int> E;
  for (int e = 1; e <= m; e++) {
    int u = fr[e], v = to[e];
    if (taken[u] || taken[v]) continue;
    E.push_back(e);
    taken[u] = taken[v] = 1;
    if (((int)E.size()) == n) return report(E, "Matching");
  }
  std::vector<int> V;
  for (int u = 1; u <= 3 * n && ((int)V.size()) < n; u++)
    if (!taken[u]) V.push_back(u);
  report(V, "IndSet");
}
int main() {
  int T;
  scanf("%d", &T);
  for (int t = 1; t <= T; t++) {
    read();
    solve();
  }
  return 0;
}
