#include <bits/stdc++.h>
using namespace std;
struct edge {
  int ind;
  int to;
};
void solve() {
  int n, m;
  cin >> n >> m;
  n *= 3;
  vector<vector<edge>> e(n + 1);
  for (int i = 1; i <= m; i++) {
    edge ed;
    ed.ind = i;
    int a, b;
    cin >> a >> b;
    ed.to = b;
    e[a].push_back(ed);
    ed.to = a;
    e[b].push_back(ed);
  }
  set<int> matched, independent;
  vector<edge> match(n + 1);
  for (int i = 1; i <= n; i++) {
    if (matched.find(i) == matched.end()) {
      bool match_found = false;
      for (int j = 0; j < e[i].size(); j++) {
        if (matched.find(e[i][j].to) == matched.end()) {
          match_found = true;
          match[i] = e[i][j];
          match[e[i][j].to] = edge{e[i][j].ind, i};
          matched.insert(i);
          matched.insert(e[i][j].to);
          break;
        }
      }
      if (!match_found) {
        independent.insert(i);
      }
    }
  }
  if (independent.size() >= n / 3) {
    cout << "IndSet" << '\n';
    int it = 0;
    for (int v : independent) {
      cout << v << ' ';
      it++;
      if (it >= n / 3) {
        break;
      }
    }
  } else {
    cout << "Matching" << '\n';
    int it = 0;
    for (int i = 1; i <= n && it < n / 3; i++) {
      if (match[i].ind != 0) {
        if (match[i].to < i) {
          cout << match[i].ind << ' ';
          it++;
        }
      }
    }
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
