#include <bits/stdc++.h>
using namespace std;
const int maxn = 510000;
struct edge {
  int x, y;
};
edge g[maxn];
int match[maxn];
int used[maxn];
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= 3 * n; i++) match[i] = -1;
  for (int i = 1; i <= m; i++) {
    cin >> g[i].x >> g[i].y;
  }
  int match_size = 0;
  for (int i = 1; i <= m; i++) {
    if (match[g[i].x] == -1 && match[g[i].y] == -1) {
      used[++match_size] = i;
      match[g[i].x] = g[i].y;
      match[g[i].y] = g[i].x;
    }
    if (match_size == n) {
      cout << "Matching" << endl;
      for (int i = 1; i <= n; i++) cout << used[i] << " ";
      cout << endl;
      return;
    }
  }
  cout << "IndSet" << endl;
  int ct = 0;
  for (int i = 1; i <= 3 * n; i++) {
    if (match[i] == -1) {
      cout << i << " ";
      ct++;
      if (ct == n) return;
    }
  }
}
int main() {
  int t;
  ios::sync_with_stdio(false);
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
