#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int T;
int n, m;
int vis[maxn];
vector<int> e;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= 3 * n; i++) vis[i] = 0;
    e.clear();
    for (int i = 1, u, v; i <= m; i++) {
      scanf("%d%d", &u, &v);
      if (vis[u] || vis[v]) continue;
      e.push_back(i);
      vis[u] = vis[v] = 1;
    }
    if (e.size() >= n) {
      puts("Matching");
      for (int i = 0; i < n; i++) printf("%d ", e[i]);
      puts("");
    } else {
      puts("IndSet");
      int cnt = 0;
      for (int i = 1; i <= 3 * n && cnt < n; i++)
        if (!vis[i]) printf("%d ", i), cnt++;
      puts("");
    }
  }
  return 0;
}
