#include <bits/stdc++.h>
using namespace std;
const long long int hell = 1000000007;
void solve() {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> used(3 * n + 5, 0);
  vector<long long int> mx;
  long long int ctr = 1;
  for (long long int i = 1; i <= m; i++) {
    long long int u, v;
    cin >> u >> v;
    if (!used[u] and !used[v]) {
      mx.push_back(i);
      used[u] = used[v] = 1;
    }
  }
  if ((long long int)((mx).size()) >= n) {
    cout << "Matching\n";
    for (long long int i = 0; i < n; i++) cout << mx[i] << ' ';
    cout << "\n";
  } else {
    cout << "IndSet\n";
    long long int ctr = n;
    for (long long int i = 1; i <= 3 * n; i++) {
      if (!used[i]) {
        cout << i << ' ';
        ctr--;
      }
      if (!ctr) break;
    }
    cout << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  for (long long int i = 0; i < t; i++) solve();
  cerr << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms"
       << '\n';
}
