#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    unordered_map<int, vector<int>> nodes;
    vector<pair<int, int>> edge;
    for (int i = 1; i <= m; i++) {
      int x, y;
      cin >> x >> y;
      edge.push_back(make_pair(x, y));
      nodes[x].push_back(y);
      nodes[y].push_back(x);
    }
    set<int> match;
    vector<int> sol1;
    for (int i = 1; i <= m; i++) {
      if ((match.count(edge[i].first) == 0) &&
          (match.count(edge[i].second) == 0)) {
        match.insert(edge[i].first);
        match.insert(edge[i].second);
        sol1.push_back(i);
      }
    }
    set<int> ind;
    for (int i = 1; i <= 3 * n; i++) {
      ind.insert(i);
    }
    for (auto i : match) ind.erase(i);
    if (sol1.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) cout << sol1[i] << ' ';
      cout << '\n';
      continue;
    }
    if (ind.size() >= n) {
      cout << "IndSet\n";
      for (int i = 0; i < n; i++) {
        cout << *ind.begin() << ' ';
        ind.erase(ind.begin());
      }
      cout << '\n';
      continue;
    }
    cout << "Impossible\n";
  }
  return 0;
}
