#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<int> matching;
    vector<int> indset;
    matching.reserve(n);
    indset.reserve(n);
    vector<int> used(3 * n + 1);
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      if (used[u] || used[v]) {
        indset.push_back(u);
        indset.push_back(v);
      } else {
        matching.push_back(i + 1);
      }
      used[u] = used[v] = true;
    }
    if ((indset).size() >= n) {
      cout << "IndSet\n";
      for (int i = 0; i < n; ++i) cout << indset[i] << " ";
    } else {
      cout << "Matching\n";
      for (int i = 0; i < n; ++i) cout << matching[i] << " ";
    }
    cout << '\n';
  }
  return 0;
}
