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