#include <bits/stdc++.h>
using namespace std;
int t, n, k, m, used[300005];
vector<int> g[300005], ans;
pair<int, int> p[500005];
int main() {
  cin >> t;
  while (t--) {
    scanf("%d%d", &k, &m);
    n = k * 3;
    ans.clear();
    for (int i = 0; i <= n; i++) {
      used[i] = 0;
      g[i].clear();
    }
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &p[i].first, &p[i].second);
      g[p[i].first].push_back(p[i].second);
      g[p[i].second].push_back(p[i].first);
    }
    for (int i = 1; i <= m; i++) {
      int u = p[i].first;
      int v = p[i].second;
      if (used[u] || used[v]) continue;
      used[u] = used[v] = 1;
      for (int j = 0; j < g[u].size(); j++) used[g[u][j]] = 2;
      for (int j = 0; j < g[v].size(); j++) used[g[v][j]] = 2;
      ans.push_back(i);
    }
    if (ans.size() < k) {
      printf("IndSet\n");
      ans.clear();
      for (int i = 1; i <= n; i++)
        if (used[i] == 2) ans.push_back(i);
    } else
      printf("Matching\n");
    for (int i = 0; i < ans.size() && i < k; i++) printf("%d ", ans[i]);
    printf("\n");
  }
  return 0;
}
