#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    n *= 3;
    unordered_set<int> pv{};
    for (int i = 1; i <= n; ++i) {
      pv.insert(i);
    }
    int a, b;
    vector<int> ans{};
    for (int i = 0; i < m; ++i) {
      cin >> a >> b;
      if (pv.find(a) != pv.end() and pv.find(b) != pv.end()) {
        ans.push_back(i + 1);
        pv.erase(a);
        pv.erase(b);
      }
    }
    if (ans.size() >= n / 3) {
      cout << "Matching\n";
      for (int i = 0; i < n / 3; ++i) {
        cout << ans[i] << " ";
      }
      cout << "\n";
    } else {
      cout << "IndSet\n";
      for (int i = 0; i < n / 3; ++i) {
        cout << *pv.begin() << " ";
        pv.erase(pv.begin());
      }
      cout << "\n";
    }
  }
  return 0;
}
