#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
const int maxn = 1000005;
struct node {
  int u, v, wei, id;
  node() {}
  node(int a, int b, int c, int d) {
    u = a;
    v = b;
    wei = c;
    id = d;
  }
} edge[maxn];
int book[maxn], b[maxn], a[maxn];
vector<int> g[maxn], ans1, ans2;
bool cmp1(int x, int y) { return g[x].size() < g[y].size(); }
bool cmp2(node x, node y) { return x.wei < y.wei; }
int indset(int n, int m) {
  for (int i = 1; i <= 3 * n; i++) book[i] = 0;
  for (int i = 1; i <= 3 * n; i++) b[i] = i;
  sort(b + 1, b + 1 + 3 * n, cmp1);
  ans1.clear();
  for (int i = 1; i <= 3 * n; i++) {
    if (ans1.size() < n && !book[b[i]]) {
      book[b[i]]++;
      ans1.push_back(b[i]);
      for (int j = 0; j < g[b[i]].size(); j++) book[g[b[i]][j]]++;
    }
  }
  if (ans1.size() == n) {
    printf("IndSet\n");
    for (int i = 0; i < n; i++) printf("%d ", ans1[i]);
    printf("\n");
    return 1;
  }
  return 0;
}
int matching(int n, int m) {
  ans2.clear();
  for (int i = 1; i <= 3 * n; i++) book[i] = 0;
  sort(edge + 1, edge + 1 + m, cmp2);
  for (int i = 1; i <= m; i++) {
    int u = edge[i].u;
    int v = edge[i].v;
    int id = edge[i].id;
    if (ans2.size() < n && !book[u] && !book[v]) {
      ans2.push_back(id);
      book[u]++;
      book[v]++;
    }
  }
  if (ans2.size() == n) {
    printf("Matching\n");
    for (int i = 0; i < n; i++) printf("%d ", ans2[i]);
    printf("\n");
    return 1;
  }
  return 0;
}
int ma(int x, int y) {
  if (x < y) swap(x, y);
  return x;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i <= 3 * n; i++) g[i].clear();
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      g[u].push_back(v);
      g[v].push_back(u);
      edge[i] = node(u, v, 0, i);
    }
    for (int i = 1; i <= m; i++)
      edge[i].wei = max(g[edge[i].u].size(), g[edge[i].v].size());
    if (indset(n, m)) continue;
    if (matching(n, m)) continue;
    printf("Impossible\n");
  }
  return 0;
}
