#include <bits/stdc++.h>
void err() { std::cout << '\n'; }
template <typename T, typename... Args>
void err(T a, Args... args) {
  std::cout << a << ' ';
  err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &...args) {
  for (auto &v : arg) std::cout << v << ' ';
  err(args...);
}
using namespace std;
const int N = 1e5 + 5, M = 5e5 + 5;
int n, m;
bool vis[N << 2];
void run() {
  cin >> n >> m;
  for (int i = 1; i <= 3 * n; i++) vis[i] = false;
  vector<int> edges;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    if (!vis[u] && !vis[v]) {
      vis[u] = vis[v] = true;
      edges.push_back(i);
    }
  }
  if ((int)(edges).size() >= n) {
    edges.resize(n);
    cout << "Matching" << '\n';
    for (auto it : edges) cout << it << ' ';
    cout << '\n';
  } else {
    cout << "IndSet" << '\n';
    int cnt = n;
    for (int i = 1; i <= 3 * n; i++)
      if (!vis[i] && cnt) {
        --cnt;
        cout << i << ' ';
      }
    cout << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(20);
  int T;
  cin >> T;
  while (T--) run();
  return 0;
}
