#include <bits/stdc++.h>
using namespace std;
int T;
int n, m;
struct Edge {
  int x, y, pos;
};
vector<Edge> E;
bool vis[500002 * 3];
int ans[500002];
void init() {
  E.clear();
  for (int i = 1; i <= 3 * n; ++i) vis[i] = 0;
}
int MatchSz() {
  srand(time(0));
  int sz = m;
  if (m == 0) {
    for (int i = 0; i < n; ++i) ans[i] = i + 1;
    return 0;
  }
  for (int i = 0; i < n && sz > 0; ++i) {
    int rd = rand() % sz;
    while (sz > 0 && (vis[E[rd].x] || vis[E[rd].y])) {
      swap(E[rd], E.back());
      E.pop_back();
      --sz;
      if (sz == 0) {
        int cnt = 0;
        for (int i = 1; i <= 3 * n; ++i)
          if (!vis[i]) ans[cnt++] = i;
        return 0;
      }
      rd = rand() % sz;
    }
    vis[E[rd].x] = vis[E[rd].y] = true;
    ans[i] = E[rd].pos;
  }
  return n;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    init();
    E.resize(m);
    for (int i = 0; i < m; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      E[i] = Edge{u, v, i + 1};
    }
    if (MatchSz() < n)
      printf("IndSet\n");
    else
      printf("Matching\n");
    for (int i = 0; i < n; ++i) printf("%d ", ans[i]);
    printf("\n");
  }
  return 0;
}
