#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> g[N];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    set<int> taken;
    vector<int> matching;
    for (int j = 1; j <= m; j++) {
      int u, v;
      cin >> u >> v;
      if (taken.count(u) || taken.count(v)) continue;
      taken.insert(u), taken.insert(v);
      if (matching.size() < n) matching.push_back(j);
    }
    if (matching.size() >= n) {
      cout << "Matching\n";
      for (auto i : matching) cout << i << " ";
      cout << "\n";
      continue;
    }
    cout << "IndSet\n";
    int cnt = 0;
    for (int j = 1; j <= n * 3 && cnt < n; j++)
      if (!taken.count(j)) {
        cout << j << " ";
        cnt++;
      }
    cout << "\n";
  }
  return 0;
}
