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