#include <bits/stdc++.h>
using namespace std;
bool compare(pair<long long int, long long int> a,
             pair<long long int, long long int> b) {
  return a.second < b.second;
}
long long int n, m, a, b, i, j, limit;
vector<pair<long long int, long long int> > edges[300001];
vector<long long int> list, sec_list;
bool mark[300001];
int graph() {
  list.clear();
  scanf("%lld%lld", &n, &m);
  for (i = 1; i <= 3 * n; i++) {
    mark[i] = 0;
    edges[i].clear();
  }
  for (i = 1; i <= m; i++) {
    scanf("%lld%lld", &a, &b);
    edges[a].push_back(make_pair(i, b));
    edges[b].push_back(make_pair(i, a));
  }
  for (i = 1; i <= 3 * n; i++) {
    sort(edges[i].begin(), edges[i].end(), compare);
  }
  for (i = 1; i <= n; i++) {
    if (mark[i] == 1) continue;
    for (j = 0; j < edges[i].size(); j++) {
      if (mark[edges[i][j].second] == 1) continue;
      if (edges[i][j].second <= n) {
        mark[i] = 1;
        mark[edges[i][j].second] = 1;
        list.push_back(edges[i][j].first);
      }
    }
  }
  if (list.size() == 0) {
    printf("IndSet\n");
    for (i = 1; i <= n; i++) printf("%lld ", i);
    printf("\n");
    return 0;
  }
  limit = n;
  while (list.size() < n) {
    sec_list.clear();
    for (i = limit + 1; i <= n + list.size() * 2; i++) {
      if (mark[i] == 1) continue;
      for (j = 0; j < edges[i].size(); j++) {
        if (mark[edges[i][j].second] == 1) continue;
        if (edges[i][j].second <= n + list.size() * 2) {
          mark[i] = 1;
          mark[edges[i][j].second] = 1;
          sec_list.push_back(edges[i][j].first);
        }
      }
    }
    limit = n + list.size() * 2;
    if (sec_list.size() == 0) {
      printf("IndSet\n");
      for (i = 1; i <= n + list.size() * 2; i++) {
        if (mark[i] != 1) printf("%lld ", i);
      }
      printf("\n");
      return 0;
    } else {
      for (j = 0; j < sec_list.size(); j++) {
        list.push_back(sec_list[j]);
      }
    }
  }
  printf("Matching\n");
  for (i = 1; i <= n; i++) printf("%lld ", list[i - 1]);
  printf("\n");
  return 0;
}
int main() {
  long long int T;
  scanf("%lld", &T);
  while (T--) {
    graph();
  }
  return 0;
}
