#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
long long __gcd(long long a, long long b) {
  while (a != 0) {
    long long __t = b % a;
    b = a;
    a = __t;
  }
  return b;
}
int main() {
  cin.tie();
  cout.tie();
  cerr.tie();
  ios_base::sync_with_stdio(false);
  unsigned _T;
  cin >> _T;
  while (_T--) {
    unsigned N, M;
    cin >> N >> M;
    vector<bool> p(3 * N + 1);
    vector<unsigned> ans;
    for (unsigned i = 1; i <= M; i++) {
      unsigned v, u;
      cin >> v >> u;
      if (!p[v] && !p[u]) {
        p[v] = p[u] = true;
        ans.push_back(i);
      }
    }
    if (ans.size() < N) {
      ans.clear();
      for (unsigned i = 1; i <= 3 * N; i++)
        if (!p[i]) ans.push_back(i);
      cout << "IndSet\n";
    } else
      cout << "Matching\n";
    ans.resize(N);
    for (auto& v : ans) cout << v << " ";
    cout << endl;
  }
  return 0;
}
