#include <bits/stdc++.h>
template <class... Args>
inline __attribute__((always_inline)) void read(Args&... args) {
  (std::cin >> ... >> args);
}
template <class... Args>
inline __attribute__((always_inline)) void write(Args&&... args) {
  (std::cout << ... << std::forward<Args>(args));
}
template <class... Args>
inline __attribute__((always_inline)) void writeln(Args&&... args) {
  write(std::forward<Args>(args)..., '\n');
}
inline __attribute__((always_inline)) void flush() { std::flush(std::cout); }
int main() {
  std::ios_base::sync_with_stdio(false);
  std::fixed(std::cout).precision(20);
  std::cin.tie(nullptr);
  int t;
  read(t);
  struct node_t {
    int a, b;
  };
  std::vector<char> used;
  std::vector<node_t> nodes;
  std::vector<int> res;
  while (t-- > 0) {
    int n, m;
    read(n, m);
    nodes.resize(m);
    for (auto& [a, b] : nodes) read(a, b), --a, --b;
    used.assign(n * 3, false);
    res.clear();
    res.reserve(m);
    for (int i = 0; i < m; ++i) {
      auto [a, b] = nodes[i];
      if (!used[a] && !used[b]) {
        used[a] |= true;
        used[b] |= true;
        res.push_back(i);
      }
    }
    if ((int)res.size() >= n) {
      writeln("Matching");
      for (int i = 0; i < n; ++i) write(res[i] + 1, ' ');
      writeln();
    } else {
      writeln("IndSet");
      int cnt = n;
      for (int i = 0; cnt; ++i)
        if (!used[i]) write(i + 1, ' '), --cnt;
      writeln();
    }
  }
  return 0;
}
