#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
const int N = (int)5e5 + 228;
using namespace std;
int n, m, used[N], timer;
vector<pair<int, int> > g[N];
vector<int> res, res1;
void dfs(int v, int type) {
  int child = 0;
  used[v] = timer;
  for (auto e : g[v]) {
    int to = e.first;
    if (used[to] == timer) continue;
    child++;
    if (type == 0) {
      res.push_back(e.second);
      dfs(to, 1);
      type = 1;
    } else {
      dfs(to, 0);
    }
  }
  if (!child) res1.push_back(v);
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n + n + n; i++) g[i].clear();
  for (int i = 1; i <= m; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    g[v].push_back({u, i});
    g[u].push_back({v, i});
  }
  res1.clear();
  timer++;
  res.clear();
  for (int i = 1; i <= n + n + n; i++) {
    if (used[i] == timer) continue;
    dfs(i, 0);
  }
  if ((int)res1.size() >= n) {
    printf("IndSet\n");
    for (int i = 0; i < n; i++) printf("%d ", res1[i]);
    printf("\n");
    return;
  }
  assert((int)res.size() >= n);
  printf("Matching\n");
  for (int i = 0; i < n; i++) printf("%d ", res[i]);
  printf("\n");
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
