#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;
    unordered_map<int, unordered_map<int, int>> edges;
    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));
      edges[x][y] = edges[y][x] = i;
      nodes[x].push_back(y);
      nodes[y].push_back(x);
    }
    set<pair<int, int>> S;
    for (int i = 1; i <= 3 * n; i++) {
      S.insert(make_pair(nodes[i].size(), i));
    }
    bool ok = 1;
    vector<int> sol;
    for (int i = 0; i < n; i++) {
      if (S.size() == 0) {
        ok = 0;
        break;
      }
      int x = S.begin()->second;
      S.erase(S.begin());
      sol.push_back(x);
      for (auto i : nodes[x]) {
        S.erase(make_pair(nodes[i].size(), i));
      }
    }
    if (ok == 1) {
      cout << "IndSet\n";
      for (auto i : sol) {
        cout << i << ' ';
      }
      cout << '\n';
      continue;
    }
    S.clear();
    ok = 1;
    for (int i = 1; i <= m; i++) {
      S.insert(make_pair(
          nodes[edge[i].first].size() + nodes[edge[i].second].size() - 1, i));
    }
    sol.clear();
    for (int i = 0; i < n; i++) {
      if (S.size() == 0) {
        ok = 0;
        break;
      }
      int x = S.begin()->second;
      S.erase(S.begin());
      sol.push_back(x);
      for (auto i : nodes[edge[x].first]) {
        S.erase(make_pair(nodes[edge[x].first].size() - 1 + nodes[i].size(),
                          edges[i][edge[x].first]));
      }
    }
    if (ok == 1) {
      cout << "Matching\n";
      for (auto i : sol) {
        cout << i << ' ';
      }
      cout << '\n';
      continue;
    }
    cout << "Impossible\n";
  }
  return 0;
}
