#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<vector<long long>> g(3 * n);
    map<pair<long long, long long>, long long> edges;
    for (long long i = 0; i < m; i++) {
      long long u, v;
      cin >> u >> v;
      u--;
      v--;
      g[u].push_back(v);
      g[v].push_back(u);
      pair<long long, long long> p = {u, v};
      edges[p] = i + 1;
      p = {v, u};
      edges[p] = i + 1;
    }
    vector<long long> matching;
    vector<long long> indset;
    vector<bool> removed(3 * n, false);
    for (long long i = 0; i < 3 * n; i++) {
      if (removed[i]) continue;
      for (auto v : g[i]) {
        if (!removed[v]) {
          pair<long long, long long> p = {i, v};
          matching.push_back(edges[p]);
          removed[i] = true;
          removed[v] = true;
          break;
        }
      }
    }
    if (matching.size() >= n) {
      cout << "Matching\n";
      cout << matching[0];
      for (long long i = 1; i < n; i++) cout << " " << matching[i];
      cout << "\n";
    } else {
      for (long long i = 0; i < 3 * n; i++) {
        if (!removed[i]) {
          indset.push_back(i + 1);
        }
      }
      cout << "IndSet\n";
      cout << indset[0];
      for (long long i = 1; i < n; i++) cout << " " << indset[i];
      cout << "\n";
    }
  }
}
