#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
int t;
vector<vector<int>> g;
vector<bool> used, taken;
map<pair<int, int>, int> edges;
vector<int> match;
void dfs(int u, bool b) {
  used[u] = true;
  bool fl = true;
  for (auto to : g[u]) {
    if (!used[to] && !b && fl) {
      fl = false;
      int tu = u, tv = to;
      if (tu > tv) swap(tu, tv);
      taken[tu] = true;
      taken[tv] = true;
      match.push_back(edges[make_pair(tu, tv)]);
    }
    if (!used[to]) dfs(to, !b);
  }
}
int main() {
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    g.assign(3 * n + 1, vector<int>());
    used.assign(3 * n + 1, false);
    taken.assign(3 * n + 1, false);
    edges.clear();
    match.clear();
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
      if (u > v) swap(u, v);
      edges.insert(make_pair(make_pair(u, v), i + 1));
    }
    for (int v = 1; v <= 3 * n; ++v) {
      if (!used[v]) dfs(v, 0);
    }
    if (match.size() < n) {
      cout << "IndSet\n";
      int k = n;
      for (int v = 1; v <= 3 * n && k > 0; ++v) {
        if (!taken[v]) {
          cout << v << ' ';
          --k;
        }
      }
      cout << '\n';
    } else {
      cout << "Matching\n";
      for (size_t i = 0; i < match.size() && n > 0; ++i, --n) {
        cout << match[i] << ' ';
      }
      cout << '\n';
    }
  }
  return 0;
}
