#include <bits/stdc++.h>
using namespace std;
int T, n, m;
vector<int> edge[300005];
vector<int> id[300005];
int vis[300005];
int E[500005];
int main() {
  cin >> T;
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= 3 * n; i++) {
      edge[i].clear();
      id[i].clear();
      vis[i] = 0;
    }
    for (int i = 1; i <= m; i++) E[i] = 0;
    int u, v;
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &u, &v);
      if (u > v) swap(u, v);
      edge[u].push_back(v);
      id[u].push_back(i);
    }
    int num = 0;
    for (int i = 1; i <= 3 * n && num < n; i++) {
      if (vis[i]) continue;
      int len = edge[i].size();
      for (int j = 0; j < len; j++) {
        int nex = edge[i][j];
        if (vis[nex] == 0) {
          vis[nex] = vis[i] = 1;
          E[id[i][j]] = 1;
          num++;
          break;
        }
      }
    }
    if (num == n) {
      printf("Matching\n");
      for (int i = 1; i <= m; i++) {
        if (E[i] == 1) printf("%d ", i);
      }
      printf("\n");
    } else {
      printf("IndSet\n");
      int tt = 0;
      for (int i = 1; i <= 3 * n && tt < n; i++)
        if (vis[i] == 0) {
          printf("%d ", i);
          tt++;
        }
      printf("\n");
    }
  }
}
