#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto i : v) os << i << " ";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v) {
  for (auto i : v) os << i << " ";
  return os;
}
unordered_set<int> node, edge;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    node.clear();
    edge.clear();
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
      int x, y;
      scanf("%d%d", &x, &y);
      if (!node.count(x) && !node.count(y)) {
        node.insert(x);
        node.insert(y);
        edge.insert(i + 1);
      }
    }
    if (edge.size() >= n) {
      cout << "Matching\n";
      cout << edge << endl;
    } else {
      cout << "IndSet\n";
      for (int i = 1; i <= 3 * n; ++i)
        if (!node.count(i)) cout << i << " ";
      cout << endl;
    }
  }
  return 0;
}
