#include <bits/stdc++.h>
using namespace std;
const int MX = 500005;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> in(3 * n + 1), a;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    if (!in[u] && !in[v]) {
      a.emplace_back(i);
      in[u] = in[v] = 1;
    }
  }
  if (a.size() >= n) {
    cout << "Matching" << '\n';
    for (int i = 0; i < n; i++) cout << a[i] << " ";
    cout << '\n';
  } else {
    cout << "IndSet" << '\n';
    int k = 0;
    for (int i = 1; i <= 3 * n && k < n; i++)
      if (!in[i]) {
        cout << i << " ";
        k++;
      }
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
