#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  vector<int> a, b;
  vector<set<int> > g;
  cin >> n >> m;
  g.clear();
  g.resize(3 * n);
  a.resize(m);
  b.resize(m);
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
    --a[i];
    --b[i];
    if (a[i] > b[i]) swap(a[i], b[i]);
    g[a[i]].insert(i);
    g[b[i]].insert(i);
  }
  vector<int> ed, ve;
  vector<int> u(3 * n, 0);
  for (int i = 0; i < 3 * n; ++i) {
    if (u[i]) continue;
    if (g[i].size() == 0)
      ve.push_back(i);
    else {
      int j = *g[i].begin();
      ed.push_back(j);
      int ii = a[j] + b[j] - i;
      u[i] = 1;
      u[ii] = 1;
      for (auto it = g[i].begin(); it != g[i].end(); ++it) {
        int jj = *it;
        g[a[jj] + b[jj] - i].erase(jj);
      }
      for (auto it = g[ii].begin(); it != g[ii].end(); ++it) {
        int jj = *it;
        g[a[jj] + b[jj] - ii].erase(jj);
      }
    }
    if (ve.size() == n) {
      cout << "IndSet\n";
      for (int e = 0; e < n; ++e) cout << 1 + ve[e] << " ";
      cout << "\n";
      return;
    }
    if (ed.size() == n) {
      cout << "Matching\n";
      for (int e = 0; e < n; ++e) cout << 1 + ed[e] << " ";
      cout << "\n";
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
