#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > edgs;
set<int> v_taken;
vector<int> match_indx;
void init() {
  edgs.clear();
  v_taken.clear();
  match_indx.clear();
}
void find_ind_set(int n, int m) {
  printf("IndSet\n");
  int printed = 0;
  for (int i = 1; i <= (3 * n); ++i) {
    if (v_taken.find(i) == v_taken.end()) {
      printf("%d ", i);
      printed++;
    }
    if (printed == n) break;
  }
  printf("\n");
}
void find_matching(int n, int m) {
  int i = 1;
  int taken = 0;
  for (auto p : edgs) {
    int u = p.first;
    int v = p.second;
    if (v_taken.find(u) == v_taken.end() && v_taken.find(v) == v_taken.end()) {
      v_taken.insert(u);
      v_taken.insert(v);
      match_indx.push_back(i);
      taken++;
    }
    if (taken == n) {
      break;
    }
    i++;
  }
  if ((match_indx.size()) == n) {
    printf("Matching\n");
    for (int idx : match_indx) {
      printf("%d ", idx);
    }
    printf("\n");
  } else {
    find_ind_set(n, m);
  }
}
int main() {
  int t;
  scanf("%d", &t);
  for (int cs = 1; cs <= t; ++cs) {
    int n, m;
    scanf("%d %d", &n, &m);
    init();
    for (int i = 1; i <= m; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      edgs.push_back(make_pair(u, v));
    }
    find_matching(n, m);
  }
  return 0;
}
