#include <bits/stdc++.h>
using namespace std;
const int _ = 5e5 + 7;
int T, n, m, vis[_];
std::vector<int> dsr;
int main() {
  scanf("%d", &T);
  while (T-- > 0) {
    scanf("%d%d", &n, &m);
    dsr.clear();
    for (int i = 1; i <= 3 * n; ++i) vis[i] = 0;
    for (int i = 1, u, v; i <= m; ++i) {
      scanf("%d%d", &u, &v);
      if (!vis[u] && !vis[v]) {
        vis[u] = vis[v] = 1;
        dsr.push_back(i);
      }
    }
    if ((int)dsr.size() >= n) {
      printf("Matching\n");
      for (int i = 0; i < n; ++i) printf("%d ", dsr[i]);
      printf("\n");
    } else {
      printf("IndSet\n");
      for (int i = 1, js = 1; js <= n; ++i)
        if (!vis[i]) printf("%d ", i), ++js;
      printf("\n");
    }
  }
  return 0;
}
