#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int>> edges;
vector<bool> visited;
void doit() {
  vector<int> matching;
  for (int i = 0; i < edges.size(); i++) {
    int u, v;
    tie(u, v) = edges[i];
    if (!visited[u] && !visited[v]) {
      matching.push_back(i);
      visited[u] = true;
      visited[v] = true;
    }
  }
  if (matching.size() >= n) {
    printf("Matching\n");
    for (int i = 0; i < n; i++) {
      printf("%d%c", matching[i] + 1, (i + 1 == n ? '\n' : ' '));
    }
  } else {
    vector<int> inds;
    for (int i = 0; i < 3 * n; i++) {
      if (!visited[i]) inds.push_back(i);
    }
    printf("IndSet\n");
    for (int i = 0; i < n; i++) {
      printf("%d%c", inds[i] + 1, (i + 1 == n ? '\n' : ' '));
    }
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T-- > 0) {
    scanf("%d%d", &n, &m);
    edges.clear();
    visited.assign(3 * n, false);
    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      u--;
      v--;
      edges.push_back({u, v});
    }
    doit();
  }
}
