#include <bits/stdc++.h>
using namespace std;
bool used[300005];
vector<long long> edges;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    for (long long i = 1; i <= 3 * n; i++) {
      used[i] = 0;
    }
    edges.clear();
    for (long long i = 0; i < m; i++) {
      long long u, v;
      cin >> u >> v;
      if (!used[u] && !used[v]) {
        edges.push_back(i + 1);
        used[u] = 1;
        used[v] = 1;
      }
    }
    if (edges.size() < n) {
      cout << "IndSet\n";
      for (long long i = 1, cnt = 0; cnt < n && i <= 3 * n; i++) {
        if (!used[i]) {
          cnt++;
          cout << i << ' ';
        }
      }
    } else {
      cout << "Matching\n";
      for (long long i = 0; i < n; i++) {
        cout << edges[i] << ' ';
      }
    }
    cout << '\n';
  }
  return 0;
}
