#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, from;
} e[2000000];
int t, tot, n, m, num1, num2, ans[2000000];
bool ed[2000000];
inline void addedge(int x, int y) {
  e[++tot].from = x;
  e[tot].to = y;
}
void init() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) ed[i] = 0;
  tot = 0;
  for (int i = 1; i <= m; i++) cin >> num1 >> num2, addedge(num1, num2);
  num1 = num2 = 0;
}
void solve() {
  for (int i = 1; i <= tot; i++) {
    if (!ed[e[i].from] && !ed[e[i].to]) {
      ans[++num1] = i;
      ed[e[i].from] = ed[e[i].to] = 1;
    }
    if (num1 == n) {
      cout << "Matching" << endl;
      for (int j = 1; j <= n; j++) cout << ans[j] << " ";
      cout << endl;
      return;
    }
  }
  cout << "IndSet" << endl;
  for (int i = 1; i <= 3 * n; i++) {
    if (!ed[i]) cout << i << " ";
  }
  cout << endl;
}
int main(void) {
  cin >> t;
  while (t--) {
    init();
    solve();
  }
}
