#include <bits/stdc++.h>
using namespace std;
vector<int> A[300010];
vector<pair<int, int> > ed;
int deg[300010];
int del[500010];
map<pair<int, int>, int> idx;
int main() {
  int t, n, m;
  int u, v;
  ios_base::sync_with_stdio(false);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    int lim = n;
    n *= 3;
    idx.clear();
    ed.clear();
    for (int i = 1; i <= n; i++) {
      A[i].clear();
      deg[i] = 0;
      del[i] = 0;
    }
    int id = 0;
    while (m--) {
      cin >> u >> v;
      A[u].push_back(v);
      A[v].push_back(u);
      deg[u]++;
      deg[v]++;
      ed.push_back(make_pair(u, v));
      idx[make_pair(min(u, v), max(u, v))] = id;
      id++;
    }
    vector<pair<int, int> > ds;
    for (int i = 1; i <= n; i++) {
      ds.push_back(make_pair(deg[i], i));
    }
    sort(ds.begin(), ds.end());
    vector<int> ind;
    for (auto x : ds) {
      if (del[x.second] == 1) continue;
      ind.push_back(x.second);
      del[x.second] = 1;
      for (int v : A[x.second]) del[v] = 1;
    }
    if (ind.size() >= lim) {
      cout << "IndSet" << endl;
      for (int i = 0; i < lim; i++) cout << ind[i] << " ";
      cout << endl;
      continue;
    }
    ds.clear();
    for (int i = 0; i < ed.size(); i++) del[i] = 0;
    for (int i = 0; i < ed.size(); i++) {
      auto e = ed[i];
      int d = max(deg[e.first], deg[e.second]);
      ds.push_back(make_pair(d, i));
    }
    sort(ds.begin(), ds.end());
    vector<int> mat;
    for (auto x : ds) {
      int u = ed[x.second].first;
      int v = ed[x.second].second;
      int id = idx[make_pair(min(u, v), max(u, v))];
      if (del[id] == 1) continue;
      del[id] = 1;
      mat.push_back(id + 1);
      for (int w : A[u]) {
        int id = idx[make_pair(min(u, w), max(u, w))];
        del[id] = 1;
      }
      for (int w : A[v]) {
        int id = idx[make_pair(min(v, w), max(v, w))];
        del[id] = 1;
      }
    }
    if (mat.size() >= lim) {
      cout << "Matching" << endl;
      for (int i = 0; i < lim; i++) cout << mat[i] << " ";
      cout << endl;
      continue;
    }
    cout << "Impossible" << endl;
  }
  return 0;
}
