#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
using namespace std;
template <typename T>
void uin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T>
void uax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
const long long N = 300 * 1000 + 228;
bool mt[N];
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= 3 * n; ++i) mt[i] = 0;
  vector<long long> pars;
  for (long long i = 0; i < m; ++i) {
    long long u, v;
    cin >> u >> v;
    if (!mt[u] && !mt[v]) {
      mt[u] = mt[v] = 1;
      pars.emplace_back(i + 1);
    }
  }
  vector<long long> mis;
  for (long long i = 1; i <= 3 * n; ++i) {
    if (!mt[i]) mis.push_back(i);
  }
  if ((long long)mis.size() >= n) {
    cout << "IndSet\n";
    while ((long long)mis.size() > n) mis.pop_back();
    for (long long i : mis) cout << i << " ";
    cout << '\n';
  } else {
    while ((long long)pars.size() > n) pars.pop_back();
    cout << "Matching\n";
    for (long long i : pars) cout << i << " ";
    cout << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
