#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const long long mod = 998244353;
const long long INF = 1e9 + 7;
const int base = 131;
const double eps = 0.0000001;
const double pi = acos(-1);
const int MAXN = 4e5 + 5;
const int MAXM = 5e5 + 5;
int n, m, cnt;
int head[MAXN], vis[MAXM * 2], du[MAXN];
struct node {
  int u, du;
  node(int u_, int du_) {
    u = u_;
    du = du_;
  }
  bool operator<(const node &a) const { return du < a.du; }
};
struct edge {
  int to, nxt, u, v, id;
} e[MAXM * 2];
void add(int u, int v, int id) {
  e[cnt].u = u, e[cnt].v = v, e[cnt].id = id;
  e[cnt].to = v;
  e[cnt].nxt = head[u];
  head[u] = cnt++;
}
vector<node> cnm;
vector<int> v, p;
int main() {
  int x, y;
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    memset(head, -1, sizeof(head));
    ;
    cnt = 0;
    memset(vis, 0, sizeof(vis));
    ;
    cnm.clear();
    v.clear();
    p.clear();
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &x, &y);
      du[x]++, du[y]++;
      add(x, y, i + 1);
      add(y, x, i + 1);
    }
    for (int i = 1; i <= 3 * n; i++) {
      cnm.push_back(node(i, du[i]));
    }
    sort(cnm.begin(), cnm.end());
    for (int i = 0; i < cnt; i++) {
      if (vis[i]) continue;
      vis[i] = vis[i ^ 1] = 1;
      v.push_back(e[i].id);
      int u = e[i].u, v = e[cnt].v;
      for (int j = head[u]; ~j; j = e[j].nxt) {
        vis[j] = vis[j ^ 1] = 1;
      }
      for (int j = head[v]; ~j; j = e[j].nxt) {
        vis[j] = vis[j ^ 1] = 1;
      }
    }
    memset(vis, 0, sizeof(vis));
    ;
    for (int s = 0; s < 3 * n; s++) {
      int i = cnm[s].u;
      if (vis[i]) continue;
      vis[i] = 1;
      p.push_back(i);
      for (int j = head[i]; ~j; j = e[j].nxt) {
        int en = e[j].to;
        vis[en] = 1;
      }
    }
    if (v.size() >= n) {
      printf("Matching\n");
      for (int i = 0; i < v.size(); i++) {
        printf("%d ", v[i]);
      }
      printf("\n");
    } else if (p.size() >= n) {
      printf("IndSet\n");
      for (int i = 0; i < p.size(); i++) {
        printf("%d ", p[i]);
      }
      printf("\n");
    }
  }
  return 0;
}
