#include <bits/stdc++.h>
using namespace std;
int T;
int n, m;
struct Edge {
  int x, y, pos;
};
vector<int> V[500002];
vector<Edge> E;
bool vis[500002];
pair<int, int> p[500002];
int ans[500002];
void init() {
  E.clear();
  for (int i = 1; i <= 3 * n; ++i) {
    vis[i] = 0;
    V[i].clear();
  }
}
void AddEdge(int u, int v) {
  V[u].push_back(v);
  V[v].push_back(u);
}
int MatchSz() {
  srand(time(0));
  int sz = m;
  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) return 0;
      rd = rand() % sz;
    }
    vis[E[rd].x] = vis[E[rd].y] = true;
    ans[i] = E[rd].pos;
  }
  return n;
}
int IndSz() {
  int cnt = 0;
  for (int i = 1; i <= 3 * n; ++i) p[i] = pair<int, int>{V[i].size(), i};
  sort(p + 1, p + n + 1);
  for (int i = 1; cnt < n && i <= 3 * n; ++i)
    if (!vis[p[i].second]) {
      ans[cnt] = p[i].second;
      vis[ans[cnt]] = true;
      for (int adj : V[ans[cnt]]) vis[adj] = true;
      ++cnt;
    }
  return cnt;
}
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};
      AddEdge(u, v);
    }
    if (MatchSz() < n) {
      if (IndSz() < n)
        printf("Impossible\n");
      else {
        printf("IndSet\n");
        for (int i = 0; i < n; ++i) printf("%d ", ans[i]);
      }
    } else {
      printf("Matching\n");
      for (int i = 0; i < n; ++i) printf("%d ", ans[i]);
    }
    printf("\n");
  }
}
