#include <bits/stdc++.h>
using namespace std;
int T, n, m;
vector<pair<int, int> > G[300005];
bool del[300005];
vector<int> matching, indset;
int main() {
  scanf("%d", &T);
  while (T--) {
    matching.clear();
    indset.clear();
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= 3 * n; i++) G[i].clear(), del[i] = false;
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      G[u].push_back(pair<int, int>(v, i));
      G[v].push_back(pair<int, int>(u, i));
    }
    for (int i = 1; i <= 3 * n; i++) {
      if (del[i]) continue;
      bool f = false;
      for (auto p : G[i]) {
        if (!del[p.first]) {
          del[p.first] = true;
          f = true;
          matching.push_back(p.second);
          break;
        }
      }
      if (!f) indset.push_back(i);
      del[i] = true;
    }
    if (matching.size() >= n) {
      puts("Matching");
      for (int i = 0; i < n; i++) printf("%d ", matching[i]);
      puts("");
    } else {
      puts("IndSet");
      for (int i = 0; i < n; i++) printf("%d ", indset[i]);
      puts("");
    }
  }
}
