#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int n, m;
vector<int> edge[maxn];
int deg[maxn];
int vis[maxn];
int need;
int hasx = 0;
vector<int> res;
void dfs(int u, int pre) {
  if (need == 0) return;
  res.push_back(u);
  need--;
  vis[u] = 1;
  for (auto v : edge[u]) {
    vis[v] = 1;
  }
}
vector<pair<int, int> > eg;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    hasx = 0;
    scanf("%d%d", &n, &m);
    need = n;
    res.clear();
    vector<int> pos(3 * n);
    for (int i = 1; i <= 3 * n; ++i)
      edge[i].clear(), deg[i] = vis[i] = 0, pos[i - 1] = i;
    eg.resize(m);
    for (int i = 1, u, v; i <= m; ++i) {
      scanf("%d%d", &u, &v);
      deg[u]++;
      deg[v]++;
      eg[i - 1] = make_pair(u, v);
      edge[u].push_back(v);
      edge[v].push_back(u);
    }
    random_shuffle(pos.begin(), pos.end());
    for (int i = 0; i < 3 * n; ++i) {
      int tt = pos[i];
      if (need == 0) break;
      if (!vis[tt]) dfs(tt, 0);
    }
    if (need == 0) {
      printf("IndSet\n");
      for (auto i : res) printf("%d ", i);
      printf("\n");
    } else {
      need = n;
      printf("Matching\n");
      for (int i = 1; i <= 3 * n; ++i) {
        vis[i] = 0;
        deg[i] = 0;
      }
      for (int i = 0; i < m; ++i) {
        if (need == 0) break;
        int tt = i;
        if (!vis[eg[tt].first] && !vis[eg[tt].second]) {
          vis[eg[tt].first] = 1;
          vis[eg[tt].second] = 1;
          printf("%d ", tt + 1);
          need--;
        }
      }
      printf("\n");
    }
  }
  return 0;
}
