#include <bits/stdc++.h>
using namespace std;
void file() {}
const long long nax = 2e5 + 1, mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  file();
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    n *= 3;
    vector<int> vis(n + 1), cnt(n + 1);
    pair<int, int> p[m + 1];
    map<pair<int, int>, int> mapp;
    for (long long i = 1; i <= m; i++) {
      cin >> p[i].first >> p[i].second;
      cnt[p[i].first]++;
      cnt[p[i].second]++;
      mapp[make_pair(p[i].first, p[i].second)] = i;
    }
    vector<pair<int, pair<int, int> > > v;
    for (long long i = 1; i <= m; i++) {
      v.push_back(make_pair(cnt[p[i].first] + cnt[p[i].second],
                            make_pair(p[i].first, p[i].second)));
    }
    sort(v.begin(), v.end());
    vector<int> ans1, ans2;
    for (auto it : v) {
      if (!vis[it.second.first] && !vis[it.second.second])
        ans1.push_back(mapp[make_pair(it.second.first, it.second.second)]),
            vis[it.second.first] = true, vis[it.second.second] = true;
    }
    for (long long i = 1; i <= n; i++) {
      if (!vis[i]) ans2.push_back(i);
    }
    if (ans1.size() >= n / 3) {
      cout << "Matching"
           << "\n";
      int ct = n / 3;
      for (auto it : ans1) {
        ct--;
        cout << it << " ";
        if (ct == 0) break;
      }
    } else {
      cout << "IndSet"
           << "\n";
      int ct = n / 3;
      for (auto it : ans2) {
        ct--;
        cout << it << " ";
        if (ct == 0) break;
      }
    }
    cout << "\n";
  }
  return 0;
}
