#include <bits/stdc++.h>
using namespace std;
void dfs(int cu, map<pair<int, int>, int> &mm, set<int> &s, vector<int> &viss,
         vector<int> &vis, vector<int> &ans, vector<vector<int>> &g) {
  if (vis[cu]) return;
  vis[cu] = 1;
  for (auto u : g[cu]) {
    if (!vis[u]) {
      if (viss[u] == 0 && viss[cu] == 0) {
        ans.push_back(mm[{cu, u}]);
        viss[cu] = 1;
        viss[u] = 1;
      }
      dfs(u, mm, s, viss, vis, ans, g);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, nn, m;
    cin >> n >> m;
    nn = n;
    n = 3 * n;
    vector<int> v, vis(n + 1, 0), ans, viss(n + 1, 0), anss;
    vector<vector<int>> g(n + 1, v);
    set<int> s;
    map<pair<int, int>, int> mm;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      g[x].push_back(y);
      g[y].push_back(x);
      mm[{x, y}] = i + 1;
      mm[{y, x}] = i + 1;
    }
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) {
        dfs(i, mm, s, viss, vis, ans, g);
      }
    }
    for (int i = 1; i <= n; i++) {
      if (viss[i] == 0) anss.push_back(i);
    }
    if (ans.size() >= nn) {
      cout << "Matching" << '\n';
      for (int i = 0; i < nn; i++) cout << ans[i] << " ";
      cout << '\n';
    } else if (anss.size() >= nn) {
      cout << "IndSet" << '\n';
      for (int i = 0; i < nn; i++) cout << anss[i] << " ";
      cout << '\n';
    } else
      cout << "Impossible" << '\n';
    ;
  }
}
