#include <bits/stdc++.h>
using namespace std;
void solve() {
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int>>> edges(3 * N + 1);
  for (int i = 1; i <= M; i++) {
    int a, b;
    cin >> a >> b;
    if (a < b) swap(a, b);
    edges[a].emplace_back(b, i);
  }
  vector<int> match;
  set<int> pool;
  for (int i = 1; i <= 3 * N; i++) {
    bool mt = false;
    for (auto& p : edges[i])
      if (pool.count(p.first)) {
        match.push_back(p.second);
        pool.erase(p.first);
        mt = true;
        break;
      }
    if (!mt) pool.insert(i);
  }
  if (pool.size() >= N) {
    cout << "IndSet" << endl;
    vector<int> pl;
    for (int a : pool) pl.push_back(a);
    for (int i = 0; i < N; i++) cout << pl[i] << " \n"[i == N - 1];
  } else {
    cout << "Matching" << endl;
    for (int i = 0; i < N; i++) cout << match[i] << " \n"[i == N - 1];
  }
}
int main() {
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
