#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P) {
  in >> P.first >> P.second;
  return in;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P) {
  out << "(" << P.first << ", " << P.second << ")";
  return out;
}
template <class T>
istream &operator>>(istream &in, vector<T> &arr) {
  for (auto &x : arr) in >> x;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<T> &arr) {
  for (auto &x : arr) out << x << ' ';
  cout << "\n";
  return out;
}
template <class T>
istream &operator>>(istream &in, deque<T> &arr) {
  for (auto &x : arr) in >> x;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const deque<T> &arr) {
  for (auto &x : arr) out << x << ' ';
  cout << "\n";
  return out;
}
const int N = 500005;
vector<int> adj[N];
int32_t main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> c(n * 3, 0);
    n *= 3;
    vector<int> opt;
    for (int i = 0; i < (n); ++i) adj[i].clear();
    for (int i = 0; i < (m); ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      --u, --v;
      adj[u].push_back(v), adj[v].push_back(i);
      if (!c[u] && !c[v]) c[u] = 1, c[v] = 1, opt.push_back(i + 1);
    }
    if (opt.size() >= n / 3) {
      puts("Matching");
      for (int i = 0; i < (n / 3); ++i) {
        printf("%d ", opt[i]);
      }
    } else {
      puts("IndSet");
      int cl = 0;
      for (int i = 0; i < (n); ++i) {
        if (!c[i]) printf("%d ", i + 1), cl++;
        if (cl == n / 3) break;
      }
    }
    printf("\n");
  }
}
