#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> g[300005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long u, v;
    for (int i = 0, ggdem = m; i < ggdem; ++i) {
      cin >> u >> v;
      u--;
      v--;
      g[u].push_back({v, i});
      g[v].push_back({u, i});
    }
    set<long long> st;
    vector<long long> mat;
    for (int i = 0, ggdem = 3 * n; i < ggdem; ++i) {
      st.insert(i);
      for (auto j : g[i]) {
        if (st.count(j.first)) {
          st.erase(i);
          st.erase(j.first);
          mat.push_back(j.second);
          break;
        }
      }
      if (((int)st.size()) == n || ((int)mat.size()) == n) break;
    }
    if (((int)st.size()) == n) {
      cout << "IndSet\n";
      for (auto i : st) cout << i + 1 << " ";
      cout << "\n";
    } else if (((int)mat.size()) == n) {
      cout << "Matching\n";
      for (auto i : mat) cout << i + 1 << " ";
      cout << "\n";
    }
    for (int i = 0, ggdem = 3 * n; i < ggdem; ++i) {
      g[i].clear();
    }
  }
  return 0;
}
