#include <bits/stdc++.h>
using namespace std;
inline void solve();
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
void solve() {
  long long T;
  cin >> T;
  for (long long t = 0; t < T; t++) {
    long long n, m;
    cin >> n >> m;
    vector<char> used(3 * n);
    long long mm = 0;
    vector<long long> ans;
    for (long long i = 0; i < m; i++) {
      long long u, v;
      cin >> u >> v;
      u--;
      v--;
      if (mm != n) {
        if (!used[u] && !used[v]) {
          mm++;
          used[u] = used[v] = true;
          ans.push_back(i + 1);
        }
      }
    }
    if (mm == n) {
      cout << "Matching\n";
      for (auto i : ans) cout << i << ' ';
    } else {
      cout << "IndSet\n";
      long long cnt = 0;
      for (long long i = 0; cnt < n && i < 3 * n; i++) {
        if (!used[i]) {
          cout << i + 1 << ' ';
          cnt++;
        }
      }
    }
    cout << '\n';
  }
}
