#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    set<int> V;
    vector<int> E;
    for (int i = 0; i < m; i++) {
      int v, u;
      cin >> v >> u;
      v--;
      u--;
      if (!V.count(v) && !V.count(u)) {
        E.push_back(i + 1);
        V.insert(v);
        V.insert(u);
      }
    }
    if (E.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) {
        cout << E[i] << " ";
      }
      cout << "\n";
    } else {
      cout << "IndSet\n";
      int out = 0;
      for (int i = 0; i < 3 * n; i++) {
        if (!V.count(i) && out < n) {
          cout << i + 1 << " ";
          out++;
        }
      }
      cout << "\n";
    }
  }
  return 0;
}
