#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int MAXN = 1e5 + 5;
void solve() {
  int n, m;
  cin >> n >> m;
  n *= 3;
  vector<pair<int, int>> g;
  set<int> used;
  set<int> all;
  for (int i = 1; i <= n; ++i) all.insert(i);
  vector<int> matching;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    g.push_back({u, v});
  }
  for (int i = 0; i < m; ++i) {
    if (!used.count(g[i].first) and !used.count(g[i].second)) {
      matching.push_back(i);
      used.insert(g[i].first);
      used.insert(g[i].second);
    }
  }
  if (matching.size() >= n / 3) {
    cout << "Matching\n";
    for (int i = 0; i < n / 3; ++i) {
      cout << matching[i] + 1 << ' ';
    }
  } else {
    set<int> q = all;
    for (auto i : used) {
      q.erase(i);
    }
    cout << "IndSet\n";
    vector<int> ans(q.begin(), q.end());
    for (int i = 0; i < n / 3; ++i) {
      cout << ans[i] << ' ';
    }
  }
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  srand(time(NULL));
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
