#include <bits/stdc++.h>
using namespace std;
const int nax = 4e5;
vector<pair<int, int>> g[nax];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<bool> used(3 * n + 1, 0), usem(3 * n + 1, 0);
    for (int i = 1; i <= 3 * n; i++) g[i].clear();
    for (int i = 1; i <= m; i++) {
      int u, v;
      cin >> u >> v;
      g[u].push_back({v, i});
      g[v].push_back({u, i});
    }
    for (int i = 1; i <= n; i++) {
      sort(g[i].begin(), g[i].end(), [&](pair<int, int> a, pair<int, int> b) {
        return g[a.first].size() < g[b.first].size();
      });
    }
    vector<int> idx;
    for (int i = 1; i <= 3 * n; i++) idx.push_back(i);
    sort(idx.begin(), idx.end(),
         [&](int a, int b) { return g[a].size() < g[b].size(); });
    vector<int> ind;
    for (int u : idx) {
      if (ind.size() == n) break;
      if (used[u] == 1) continue;
      ind.push_back(u);
      used[u] = 1;
      for (auto cur : g[u]) {
        int v = cur.first;
        used[v] = 1;
      }
    }
    if (ind.size() == n) {
      cout << "IndSet" << endl;
      for (int i : ind) cout << i << ' ';
      cout << endl;
      continue;
    }
    vector<int> mat;
    for (int u : idx) {
      if (mat.size() == n) break;
      if (usem[u] == 1 || g[u].size() == 0) continue;
      bool take = 0;
      for (auto cur : g[u]) {
        int v = cur.first;
        if (usem[v] == 1) continue;
        if (!take) {
          take = 1;
          usem[u] = 1;
          mat.push_back(cur.second);
          usem[v] = 1;
        }
      }
    }
    if (mat.size() == n) {
      cout << "Matching" << endl;
      for (int i : mat) cout << i << ' ';
      cout << endl;
      continue;
    }
    cout << "Impossible" << endl;
  }
}
