#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 7;
vector<pair<long long, long long> > g[N];
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= 3 * n; ++i) g[i].clear();
  for (long long i = 0; i < m; ++i) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back({v, i + 1});
    g[v].push_back({u, i + 1});
  }
  set<long long> mat, ind;
  for (long long u = 1; u <= 3 * n; ++u) {
    bool add = 1;
    for (auto e : g[u]) {
      if (ind.find(e.first) != ind.end()) {
        ind.erase(e.first);
        mat.insert(e.second);
        add = 0;
        break;
      }
    }
    if (add) ind.insert(u);
    if (mat.size() >= n) {
      cout << "Matching\n";
      for (long long e : mat) cout << e << ' ';
      cout << '\n';
      return;
    }
    if (ind.size() >= n) {
      cout << "IndSet\n";
      for (long long e : ind) cout << e << ' ';
      cout << '\n';
      return;
    }
  }
  exit(1);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
}
