#include <bits/stdc++.h>
using namespace std;
int n_test, n, m;
void Main() {
  cin >> n >> m;
  vector<pair<int, int> > edge(m);
  for (auto &_ : edge) cin >> _.first >> _.second;
  vector<bool> exist(3 * n + 5, 0);
  vector<int> choose;
  for (int i = 0; i < (int)edge.size(); ++i) {
    auto _ = edge[i];
    if (exist[_.first] || exist[_.second]) continue;
    choose.push_back(i + 1);
    exist[_.first] = 1;
    exist[_.second] = 1;
  }
  if ((int)choose.size() >= n) {
    cout << "Matching\n";
    for (int i = 0; i < n; ++i) cout << choose[i] << ' ';
    cout << '\n';
  } else {
    cout << "IndSet\n";
    for (int cnt = 0, u = 1; u <= 3 * n && cnt < n; ++u)
      if (!exist[u]) {
        cout << u << ' ';
        ++cnt;
      }
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n_test;
  while (n_test--) Main();
  return 0;
}
