#include <bits/stdc++.h>
using namespace std;
const long long MAXN = (int)3e5 + 5;
const long long INF = (int)1e8;
const long long mod = (int)1e9 + 7;
const long long N = (int)1e5 + 1;
mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > e;
    for (int i = 1; i <= m; i++) {
      int u, v;
      cin >> u >> v;
      e.push_back({u, v});
    }
    vector<bool> used(3 * n + 5, false);
    vector<int> a, b;
    for (int i = 0; i < m; i++) {
      if (!used[e[i].first] && !used[e[i].second]) {
        used[e[i].first] = used[e[i].second] = true;
        a.push_back(i + 1);
      } else {
        if (used[e[i].first]) {
          b.push_back(e[i].second);
        } else {
          b.push_back(e[i].first);
        }
      }
    }
    if ((int)a.size() >= n) {
      cout << "Matching\n";
      for (auto i = 0; i < n; i++) {
        cout << a[i] << ' ';
      }
      cout << '\n';
    } else {
      cout << "IndSet\n";
      int cnt = 0;
      for (auto i = 1; i <= 3 * n; i++) {
        if (cnt < n && !used[i]) {
          cout << i << ' ';
          cnt++;
        }
      }
      cout << '\n';
    }
  }
  return 0;
}
