#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T>
using vec = std::vector<T>;
bool __hack = std::ios::sync_with_stdio(false);
auto __hack1 = cin.tie(nullptr);
struct Input {
  Input(istream &in) : in(&in) {}
  template <class T>
  T next() const {
    T x;
    *in >> x;
    return x;
  }
  int ni() const { return next<int>(); }
  istream *in;
};
Input in(cin);
class Output {
 private:
  ostream *out;
  template <typename T>
  void printSingle(const T &value) {
    *out << value;
  }

 public:
  Output(ostream &out) : out(&out) {}
  inline void print() {}
  template <typename T, typename... Ts>
  inline void print(const T &f, const Ts &...args) {
    printSingle(f);
    if (sizeof...(args) != 0) {
      *out << ' ';
      print(args...);
    }
  }
  template <typename... Ts>
  inline void println(const Ts &...args) {
    print(args...);
    *out << '\n';
  }
  template <typename... Ts>
  inline void operator()(const Ts &...args) {
    println(args...);
  }
  template <typename T>
  ostream &operator<<(const T &x) {
    *out << x;
    return *out;
  }
};
Output out(cout);
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N>
struct bytetype {};
template <uint64_t N>
struct minimal_uint : bytetype<bytecount(N)> {};
}  // namespace template_util
void solveOne() {
  auto n = in.ni();
  auto m = in.ni();
  vec<pair<int, int>> edges(m);
  for (int i = 0; i < (m); ++i) {
    auto x = in.ni() - 1;
    auto y = in.ni() - 1;
    if (x > y) swap(x, y);
    edges[i] = {x, y};
  }
  vec<int> used(3 * n, 0);
  vec<int> takenEdges;
  for (int i = 0; i < (m); ++i) {
    if (!used[edges[i].first] && !used[edges[i].second]) {
      takenEdges.push_back(i);
      used[edges[i].first] = true;
      used[edges[i].second] = true;
    }
    if (takenEdges.size() == n) {
      out("Matching");
      for (const auto &e : takenEdges) {
        out << e + 1 << " ";
      }
      out();
      return;
    }
  }
  out("IndSet");
  int cnt = 0;
  for (int i = 0; i < (3 * n); ++i) {
    if (!used[i]) {
      out << i + 1 << " ";
      ++cnt;
    }
    if (cnt == n) break;
  }
  out();
}
void solve(istream &inStream, ostream &outStream) {
  in = Input(inStream);
  out = Output(outStream);
  auto tests = in.ni();
  while (tests--) {
    solveOne();
  }
}
int main() {
  solve(cin, cout);
  return 0;
}
