#include <bits/stdc++.h>
using namespace std;
const long double E = 2.71828182845904523536;
const long double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long inf = 1LL << 30;
const int N = 300300;
int deg[N], tdeg[N];
vector<int> adj[N];
vector<int> ans;
map<pair<int, int>, int> eid;
bool rem[N];
int n, m;
bool IndSet() {
  set<pair<int, int>, greater<pair<int, int>>> s;
  for (int i = 1; i <= n; i++) {
    tdeg[i] = deg[i];
    s.insert({deg[i], i});
  }
  while (1) {
    int d = (*s.begin()).first;
    int u = (*s.begin()).second;
    if (!d) break;
    s.erase(s.begin());
    for (auto v : adj[u]) {
      s.erase({tdeg[v], v});
      tdeg[v]--;
      s.insert({tdeg[v], v});
    }
  }
  if (s.size() < n / 3) return 0;
  for (auto x : s) ans.push_back(x.second);
  return 1;
}
bool Matching() {
  set<pair<int, int>> s;
  for (int i = 1; i <= n; i++) {
    tdeg[i] = deg[i];
    s.insert({deg[i], i});
  }
  while (ans.size() < n / 3) {
    int u = (*s.begin()).second;
    int v = -1, d = n;
    s.erase(s.begin());
    if (!adj[u].size() || rem[u]) continue;
    for (auto vv : adj[u]) {
      if (!rem[vv] && tdeg[vv] < d) {
        d = tdeg[vv];
        v = vv;
      }
    }
    if (v == -1) continue;
    rem[u] = rem[v] = 1;
    ans.push_back(eid[{u, v}]);
    s.erase({tdeg[v], v});
    for (auto w : adj[u]) {
      if (w == v) continue;
      s.erase({tdeg[w], w});
      tdeg[w]--;
      s.insert({tdeg[w], w});
    }
    for (auto w : adj[v]) {
      if (w == u) continue;
      s.erase({tdeg[w], w});
      tdeg[w]--;
      s.insert({tdeg[w], w});
    }
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    n *= 3;
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      adj[u].push_back(v);
      adj[v].push_back(u);
      deg[u]++;
      deg[v]++;
      eid[{u, v}] = eid[{v, u}] = i;
    }
    if (IndSet())
      printf("IndSet\n");
    else {
      printf("Matching\n");
      Matching();
    }
    int sz = n / 3;
    for (int i = 0; i < sz; i++) printf("%d%c", ans[i], " \n"[i == sz - 1]);
    eid.clear();
    ans.clear();
    for (int i = 1; i <= n; i++) {
      adj[i].clear();
      deg[i] = 0;
      rem[i] = 0;
    }
  }
  return 0;
}
