#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1e9 + 7;
constexpr int INF = INT32_MAX;
constexpr int MAXN = 3e5 + 10;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
using Vec = vector<int>;
using ll = long long;
ll N, M, K, T;
Vec A;
vector<Pii> gph[MAXN];
Vec vis;
void Solution() {
  Vec edges;
  vis.assign(3 * N, 0);
  for (int i = (int)(0); i < (int)(3 * N); ++i) {
    if (!vis[i]) {
      for (auto &p : gph[i]) {
        if (!vis[p.first]) {
          vis[i] = true;
          vis[p.first] = true;
          edges.emplace_back(p.second);
          break;
        }
      }
    }
  }
  if (edges.size() >= N) {
    cout << "Matching\n";
    for (int i = (int)(0); i < (int)(N); ++i) {
      cout << edges[i] << ' ';
    }
    cout << '\n';
  } else {
    Vec verts;
    for (int i = (int)(0); i < (int)(3 * N); ++i) {
      if (!vis[i]) {
        verts.emplace_back(i + 1);
      }
    }
    if (verts.size() >= N) {
      cout << "IndSet\n";
      for (int i = (int)(0); i < (int)(N); ++i) {
        cout << verts[i] << ' ';
      }
      cout << '\n';
    } else {
      cout << "Impossible\n";
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  while (cin >> T) {
    while (T--) {
      cin >> N >> M;
      for (int i = (int)(0); i < (int)(3 * N + 1); ++i) gph[i].clear();
      int u, v;
      for (int i = (int)(0); i < (int)(M); ++i) {
        cin >> u >> v;
        --u, --v;
        gph[u].emplace_back(v, i + 1);
        gph[v].emplace_back(u, i + 1);
      }
      Solution();
    }
  }
  return 0;
}
