#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
struct node {
  int u, v;
};
node edge[maxn];
int vis[maxn];
int ans[maxn];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m, cnt = 0;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= 3 * n; i++) {
      vis[i] = 0;
    }
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &edge[i].u, &edge[i].v);
      if (!vis[edge[i].u] && !vis[edge[i].v]) {
        ans[cnt++] = i + 1;
        vis[edge[i].u] = 1;
        vis[edge[i].v] = 1;
      }
    }
    if (cnt >= n) {
      printf("Matching\n");
      for (int i = 0; i < n; i++) {
        printf("%d%c", ans[i], i == n - 1 ? '\n' : ' ');
      }
    } else {
      printf("IndSet\n");
      cnt = 0;
      for (int i = 1; i <= 3 * n; i++) {
        if (!vis[i]) {
          cnt++;
          printf("%d%c", i, cnt == n ? '\n' : ' ');
          if (cnt == n) {
            break;
          }
        }
      }
    }
  }
}
