#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  set<int> taken;
  vector<int> matching;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    if (taken.find(u) == taken.end() && taken.find(v) == taken.end()) {
      matching.push_back(i);
      taken.insert(u);
      taken.insert(v);
    }
  }
  if (matching.size() >= n) {
    cout << "Matching\n";
    for (int i = 0; i < n; i++) cout << matching[i] << " ";
    cout << "\n";
    return;
  }
  cout << "IndSet\n";
  for (int i = 1, j = 1; j <= n; i++) {
    if (taken.find(i) == taken.end()) {
      cout << i << " ";
      j++;
    }
  }
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int testcase = 1;
  cin >> testcase;
  for (int i = 1; i <= testcase; i++) {
    solve();
  }
  return 0;
}
