#include <bits/stdc++.h>
struct Node {
  std::vector<int> to, edge_id;
};
int main() {
  int t;
  std::cin >> t;
  for (int i = 0; i < t; i++) {
    int n, m;
    std::cin >> n >> m;
    std::vector<Node> node(3 * n);
    for (int j = 0; j < m; j++) {
      int u, v;
      std::cin >> u >> v;
      u--;
      v--;
      node[u].to.push_back(v);
      node[u].edge_id.push_back(j);
      node[v].to.push_back(u);
      node[v].edge_id.push_back(j);
    }
    std::vector<bool> used(3 * n, false);
    std::vector<int> indset, matching;
    for (int j = 0; j < 3 * n; j++) {
      if (used[j] == false) {
        for (int k = 0; k < node[j].to.size(); k++) {
          if (used[k] == false) {
            used[j] = used[k] = true;
            matching.push_back(node[j].edge_id[k]);
            break;
          }
        }
        if (used[j] == false) {
          indset.push_back(j);
          used[j] = true;
        }
      }
    }
    if (indset.size() >= n) {
      std::cout << "IndSet" << std::endl;
      for (int j = 0; j < n; j++) {
        if (j > 0) {
          std::cout << ' ';
        }
        std::cout << indset[j] + 1;
      }
      std::cout << std::endl;
    } else {
      std::cout << "Matching" << std::endl;
      for (int j = 0; j < n; j++) {
        if (j > 0) {
          std::cout << ' ';
        }
        std::cout << matching[j] + 1;
      }
      std::cout << std::endl;
    }
  }
  return 0;
}
