#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  long long t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    unordered_map<int, vector<pair<long long, long long>>> g;
    pair<int, int> p[m];
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      g[a].push_back(make_pair(b, i + 1));
      g[b].push_back(make_pair(a, i + 1));
      p[i] = make_pair(a, b);
    }
    unordered_map<int, int> res, pa;
    for (auto i : g) {
      if (!res.count(i.first)) {
        for (auto j : i.second) {
          if (!res.count(j.first)) {
            if (!pa.count(j.second)) res[i.first]++;
            res[j.first]++;
            pa[j.second]++;
            break;
          }
        }
      }
    }
    unordered_map<int, int> rem;
    for (int i = 1; i <= 3 * n; i++) {
      if (!res.count(i)) {
        rem[i]++;
      }
    }
    if (rem.size() >= n) {
      cout << "IndSet" << endl;
      int x = 0;
      for (auto i : rem) {
        cout << i.first << " ";
        x++;
        if (x == n) break;
      }
      cout << endl;
    } else {
      cout << "Matching" << endl;
      int x = 0;
      for (auto i : pa) {
        cout << i.first << " ";
        x++;
        if (x == n) break;
      }
      cout << endl;
    }
  }
}
