#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > g(3 * n);
  vector<bool> used(3 * n, false);
  vector<pair<int, int> > edges;
  vector<int> matched;
  for (int i = 0; i < m; i++) {
    int from, to;
    cin >> from >> to;
    from--;
    to--;
    g[from].push_back(to);
    g[to].push_back(from);
    edges.push_back(make_pair(from, to));
  }
  for (int i = 0; i < m; i++) {
    auto e = edges[i];
    if (!used[e.first] && !used[e.second]) {
      if ((int)matched.size() < n) matched.push_back(i);
      used[e.first] = used[e.second] = true;
    }
  }
  int cnt = n;
  if ((int)matched.size() < n) {
    cout << "IndSet\n";
    for (int i = 0; cnt > 0; i++)
      if (!used[i]) cout << i + 1 << ' ', cnt--;
  } else {
    cout << "Matching\n";
    for (int x : matched) cout << x + 1 << ' ';
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
