#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
ostream& operator<<(ostream& stream, pair<P, Q> v) {
  stream << "(" << v.first << ',' << v.second << ")";
  return stream;
}
template <class T>
ostream& operator<<(ostream& stream, const vector<T> v) {
  stream << "[ ";
  for (int i = 0; i < (int)v.size(); i++) stream << v[i] << " ";
  stream << "]";
  return stream;
}
template <class T>
T smin(T& a, T b) {
  if (a > b) a = b;
  return a;
}
template <class T>
T smax(T& a, T b) {
  if (a < b) a = b;
  return a;
}
const int N = 3e6 + 5;
int was[N];
int w[N];
int main(void) {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= 3 * n; ++i) was[i] = 0, w[i] = 0;
    vector<int> Edges, Vertices;
    vector<pair<int, int> > e;
    for (int i = 0; i < m; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      e.push_back(make_pair(u, v));
      w[u] = w[v] = 1;
      if (!was[u] && !was[v]) {
        Edges.push_back(i);
        was[u] = was[v] = 1;
      }
    }
    if (Edges.size() >= n) {
      printf("Matching\n");
      Edges.resize(n);
      for (int i = 0; i < n; ++i)
        printf("%d%c", Edges[i] + 1, " \n"[i == n - 1]);
    } else {
      for (int i = 1; i <= 3 * n; ++i)
        if (!w[i] && Vertices.size() < n) Vertices.push_back(i);
      for (auto it : e)
        if (!was[it.first] || !was[it.second]) {
          if (!was[it.first] && Vertices.size() < n)
            Vertices.push_back(it.first);
          if (!was[it.second] && Vertices.size() < n)
            Vertices.push_back(it.second);
          was[it.first] = was[it.second] = 1;
        }
      printf("IndSet\n");
      for (int i = 0; i < n; ++i)
        printf("%d%c", Vertices[i], " \n"[i == n - 1]);
    }
  }
  return 0;
}
