#include <bits/stdc++.h>
using namespace std;
const int LEN = (int)3e5;
int q, n, m;
vector<pair<int, int>> g[LEN];
void out(vector<int>& ans) {
  for (int i = 0; i < n / 3; i++) cout << ans[i] + 1 << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> q;
  while (q--) {
    cin >> n >> m;
    n *= 3;
    for (int i = 0; i < n; i++) g[i].clear();
    for (int i = 0; i < m; i++) {
      int v, u;
      cin >> v >> u;
      v--;
      u--;
      g[v].push_back({u, i});
      g[u].push_back({v, i});
    }
    bitset<LEN> f;
    vector<int> match, ind;
    for (int i = 0; i < n; i++)
      if (!f[i]) {
        for (auto e : g[i])
          if (!f[e.first]) {
            f.set(i);
            f.set(e.first);
            match.push_back(e.second);
            break;
          }
        if (!f[i]) {
          f.set(i);
          ind.push_back(i);
        }
      }
    if ((int)(match).size() >= n / 3) {
      cout << "Matching\n";
      out(match);
    } else {
      cout << "IndSet\n";
      out(ind);
    }
  }
  return 0;
}
