#include <bits/stdc++.h>
using namespace std;
int t, n, m, first, second, v[300005], s;
vector<pair<int, int> > g[300005];
vector<int> l;
void DFS1(int nod) {
  v[nod] = 1;
  bool leaf = 1;
  for (pair<int, int> i : g[nod]) {
    if (!v[i.first]) {
      leaf = 0;
      DFS1(i.first);
    }
  }
  if (leaf) l.push_back(nod);
}
void DFS2(int nod, int t) {
  v[nod] = 1;
  for (pair<int, int> i : g[nod]) {
    if (!v[i.first] && t && s) {
      t = 0;
      cout << i.second << ' ';
      s--;
      DFS2(i.first, 0);
    } else if (!v[i.first]) {
      DFS2(i.first, 1);
    }
  }
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= 3 * n; i++) g[i].clear(), v[i] = 0, l.clear();
    for (int i = 1; i <= m; i++) {
      cin >> first >> second;
      g[first].push_back({second, i});
      g[second].push_back({first, i});
    }
    for (int i = 1; i <= 3 * n; i++) {
      if (!v[i]) DFS1(i);
    }
    if (l.size() >= n) {
      cout << "IndSet\n";
      for (int i = 1; i <= n; i++) cout << l[i - 1] << ' ';
      cout << '\n';
    } else {
      cout << "Matching\n";
      for (int i = 1; i <= 3 * n; i++) v[i] = 0;
      s = n;
      for (int i = 1; i <= 3 * n; i++) {
        if (!v[i]) DFS2(i, 1);
      }
      cout << '\n';
    }
  }
}
