#include <bits/stdc++.h>
using namespace std;
pair<int, int> E[500005];
set<int> S;
vector<int> V, G[300005];
int T, n, m, an;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    S.clear();
    V.clear();
    for (int i = 1; i <= 3 * n; i++) G[i].clear();
    for (int i = 1, u, v; i <= m; i++) {
      scanf("%d%d", &u, &v);
      G[u].push_back(v), G[v].push_back(u);
      E[i] = {u, v};
    }
    for (int i = 1; i <= m; i++)
      if (!S.count(E[i].first) && !S.count(E[i].second)) {
        S.insert(E[i].first), S.insert(E[i].second);
        V.push_back(i);
        if (V.size() == n) break;
      }
    if (V.size() == n) {
      puts("Matching");
      for (int &j : V) printf("%d ", j);
      puts("");
    } else {
      puts("IndSet");
      int p = 0;
      while (V.size() < n) {
        S.clear();
        V.clear();
        for (int i = ++p; i <= n * 3; i++)
          if (!S.count(i)) {
            V.push_back(i);
            for (int &j : G[i]) S.insert(j);
            if (V.size() == n) break;
          }
      }
      for (int &j : V) printf("%d ", j);
      puts("");
    }
  }
  return 0;
}
