#include <bits/stdc++.h>
using namespace std;
bool match(vector<pair<pair<int, int>, int> > &edges, int N) {
  vector<int> vivo(3 * N, 1);
  vector<int> res;
  for (auto &x : edges) {
    if (vivo[x.first.first] && vivo[x.first.second]) {
      vivo[x.first.first] = 0;
      vivo[x.first.second] = 0;
      res.push_back(x.second);
    }
  }
  if (res.size() >= N) {
    cout << "Matching\n";
    for (int i = 0; i < N; i++) cout << res[i] + 1 << " \n"[i == N - 1];
    return 1;
  }
  vector<int> res2;
  for (int i = 0; i < 3 * N; i++)
    if (vivo[i]) res2.push_back(i);
  if (res2.size() >= N) {
    cout << "IndSet\n";
    for (int i = 0; i < N; i++) cout << res2[i] + 1 << " \n"[i == N - 1];
    return 1;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int N, M;
    cin >> N >> M;
    vector<pair<pair<int, int>, int> > edges(M);
    for (int i = 0; i < M; i++) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      edges[i] = {{u, v}, i};
    }
    if (match(edges, N)) continue;
    cout << "Impossible\n";
  }
  return 0;
}
