#include <bits/stdc++.h>
using namespace std;
inline void updMx(int &a, int b) {
  if (a < b) a = b;
}
inline void updMi(int &a, int b) {
  if (a > b) a = b;
}
const int INF = 1e9 + 9;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<deque<int> > g(3 * n);
    map<pair<int, int>, int> ind;
    for (int i = (int)(0); i < (int)(m); ++i) {
      int u, v;
      cin >> u >> v;
      --u, --v;
      ind[{u, v}] = i;
      ind[{v, u}] = i;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    vector<pair<int, int> > es;
    vector<int> used(3 * n, 0);
    int can = 0;
    while (can < 3 * n && es.size() < n) {
      auto u = can;
      if (used[u]) {
        can++;
        continue;
      }
      int v = -1;
      while (!g[u].empty()) {
        if (!used[g[u][0]]) {
          v = g[u][0];
          g[u].pop_front();
          break;
        }
        g[u].pop_front();
      }
      if (v == -1) {
        can++;
        continue;
      }
      used[u] = used[v] = 1;
      es.push_back({u, v});
      can++;
    }
    if (es.size() == n) {
      cout << "Matching\n";
      for (auto ix : es) cout << ind[ix] + 1 << ' ';
      cout << '\n';
    } else {
      vector<int> ans;
      for (int i = (int)(0); i < (int)(3 * n); ++i) {
        if (!used[i] && ans.size() < n) ans.push_back(i);
      }
      if (ans.size() == n) {
        cout << "IndSet\n";
        for (auto ix : ans) cout << ix + 1 << ' ';
        cout << '\n';
      } else
        cout << "Impossible\n";
    }
  }
  return 0;
}
