#include <bits/stdc++.h>
using namespace std;
pair<int, int> edg[500111];
int visited[500111];
int ans[500111];
int main() {
  int T;
  scanf("%d", &T);
  while (T > 0) {
    int n, m, i;
    scanf("%d%d", &n, &m);
    for (i = 1; i <= 3 * n; ++i) {
      visited[i] = 0;
    }
    for (i = 1; i <= m; ++i) scanf("%d%d", &edg[i].first, &edg[i].second);
    int cnt = 0;
    for (i = 1; i <= m; ++i) {
      if (!visited[edg[i].first] && !visited[edg[i].second]) {
        cnt++;
        ans[cnt] = i;
        visited[edg[i].first] = visited[edg[i].second] = 1;
      }
      if (cnt >= n) break;
    }
    if (cnt >= n) {
      printf("Matching\n");
      for (i = 1; i <= cnt; ++i) {
        printf("%d ", ans[i]);
      }
      printf("\n");
    } else {
      printf("IndSet\n");
      for (i = 1, cnt = 1; i <= 3 * n && cnt <= n; ++i) {
        if (!visited[i]) {
          printf("%d ", i);
          cnt++;
        }
      }
      printf("\n");
    }
    T--;
  }
  return 0;
}
