#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t;
  cin >> t;
  for (; t > 0; t--) {
    long long n, m;
    cin >> n >> m;
    n *= 3;
    vector<long long> a((size_t)n, 0);
    vector<long long> b;
    for (long long i = 0; i < n; i++) {
      long long u, v;
      cin >> u >> v;
      u--, v--;
      if (a[u] == 0 && a[v] == 0) {
        a[u] = 1, a[v] = 1;
        b.push_back(i);
      }
    }
    if (accumulate(a.begin(), a.end(), (long long)0) >= n / 3) {
      cout << "Matching"
           << "\n";
      long long j = 0;
      for (long long i : b) {
        cout << i + 1 << " ";
        j++;
        if (j >= n / 3) {
          break;
        }
      }
      cout << "\n";
    } else {
      cout << "IndSet"
           << "\n";
      for (long long i = 0, j = 0; i < n && j < n / 3; i++) {
        if (a[i] == 0) {
          cout << i + 1 << " ";
          j++;
        }
      }
      cout << "\n";
    }
  }
  return 0;
}
