#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
const int maxn = 1e5 + 5;
const int maxm = 5e5 + 5;
int head[maxn * 3], tot;
struct Edge {
  int v;
  int next;
  int id;
} edge[maxm << 1];
bool vis[maxn * 3];
vector<int> E;
void init(int n) {
  E.clear();
  fill(vis, vis + 3 * n + 1, 0);
  fill(head, head + 3 * n + 1, 0);
  tot = 0;
}
inline void AddEdge(int u, int v, int id) {
  edge[++tot].v = v;
  edge[tot].id = id;
  edge[tot].next = head[u];
  head[u] = tot;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m, u, v;
    scanf("%d%d", &n, &m);
    init(n);
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &u, &v);
      AddEdge(u, v, i);
      AddEdge(v, u, i);
    }
    int cnt = 0;
    for (int i = 1; i <= 3 * n; i++) {
      bool flag = false;
      for (int j = head[i]; j; j = edge[j].next) {
        if (vis[edge[j].v]) {
          flag = true;
          vis[edge[j].v] = false;
          E.push_back(edge[j].id);
          break;
        }
      }
      if (!flag)
        vis[i] = true, cnt++;
      else
        cnt--;
    }
    if (cnt >= n) {
      cnt = n;
      printf("IndSet\n");
      for (int i = 1; i <= 3 * n && cnt; i++) {
        if (vis[i]) {
          printf("%d ", i);
          cnt--;
        }
      }
      printf("\n");
    } else {
      printf("Matching\n");
      for (int i = 0; i < n; i++) {
        printf("%d ", E[i]);
      }
      printf("\n");
    }
  }
}
