#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pairll = pair<ll, ll>;
using vvll = vector<vll>;
using vint = vector<int>;
using pint = pair<int, int>;
using vvint = vector<vint>;
void solve() {
  int n, m;
  cin >> n >> m;
  vvint edges(3 * n);
  set<pint> existing;
  int u, v;
  map<pint, int> time;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    if (u > v) {
      swap(u, v);
    }
    time[make_pair(u, v)] = i, edges[u].push_back(v);
    edges[v].push_back(u);
    existing.insert(make_pair(u, v));
  }
  set<int> matching;
  set<int> indep;
  for (int i = 0; i < 3 * n; i++) {
    indep.insert(i);
  }
  int x, y;
  while (!existing.empty()) {
    u = existing.begin()->first;
    v = existing.begin()->second;
    if (u > v) {
      swap(u, v);
    }
    matching.insert(time[make_pair(u, v)]);
    indep.erase(u);
    indep.erase(v);
    for (int i : edges[u]) {
      x = min(i, u);
      y = max(i, u);
      existing.erase(make_pair(x, y));
    }
    for (int i : edges[v]) {
      x = min(i, v);
      y = max(i, v);
      existing.erase(make_pair(x, y));
    }
  }
  if (matching.size() >= n) {
    cout << "Matching" << '\n';
    auto it = matching.begin();
    for (int i = 0; i < n; i++) {
      cout << *it + 1 << ' ';
      ++it;
    }
    cout << '\n';
  } else if (indep.size() >= n) {
    cout << "IndSet" << '\n';
    auto it = indep.begin();
    for (int i = 0; i < n; i++) {
      cout << *it + 1 << ' ';
      ++it;
    }
    cout << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
