#include <bits/stdc++.h>
using namespace std;
int used[300005];
vector<int> ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    ans.clear();
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= 3 * n; i++) used[i] = 0;
    for (int i = 1; i <= m; i++) {
      int x, y;
      cin >> x >> y;
      if (!used[x] && !used[y]) {
        used[x] = 1;
        used[y] = 1;
        ans.push_back(i);
      }
    }
    if (ans.size() < n) {
      cout << "IndSet" << '\n';
      ans.clear();
      for (int i = 1; i < 3 * n; i++) {
        if (!used[i]) ans.push_back(i);
      }
    } else
      cout << "Matching" << '\n';
    for (int i = 0; i < n; i++) {
      cout << ans[i];
      if (i == n - 1)
        cout << '\n';
      else
        cout << ' ';
    }
  }
  return 0;
}
