#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2.1e5;
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    vector<pair<int, int> > E;
    int n, m;
    cin >> n >> m;
    map<pair<int, int>, int> indmap;
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      E.emplace_back(u, v);
      indmap[make_pair(u, v)] = i + 1;
    }
    vector<bool> covered(3 * n + 1);
    vector<pair<int, int> > match;
    for (int i = 0; i < m; i++) {
      int u = E[i].first;
      int v = E[i].second;
      if (!covered[u] && !covered[v]) {
        covered[u] = true;
        covered[v] = true;
        match.push_back(E[i]);
      }
    }
    if (match.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) {
        cout << indmap[match[i]] << ' ';
      }
      cout << '\n';
    } else {
      cout << "IndSet\n";
      int need = n;
      for (int i = 1; i <= 3 * n; i++) {
        if (need == 0) break;
        if (!covered[i]) {
          cout << i << ' ';
          need--;
        }
      }
      cout << '\n';
    }
  }
  return 0;
}
