#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, m;
    cin >> n >> m;
    vector<int> used(3 * n + 1), ans1;
    for (int i = 1; i <= m; i++) {
      int a, b;
      cin >> a >> b;
      if (used[a] == 0 && used[b] == 0)
        ans1.push_back(i), used[a] = used[b] = 1;
    }
    if (ans1.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) cout << ans1[i] << " ";
    } else {
      cout << "IndSet\n";
      for (int i = 1; i <= 3 * n; i++)
        if (used[i] == 0) cout << i << " ";
    }
    cout << "\n";
  }
  return 0;
}
