#include <bits/stdc++.h>
using namespace std;
const int NIL = -1;
template <class T>
inline T mx(T a, T b) {
  return a > b ? a : b;
}
template <class T>
inline T mi(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline void sw(T &a, T &b) {
  T t = a;
  a = b;
  b = t;
}
template <class T>
inline T mabs(T x) {
  return x < 0 ? -x : x;
}
inline char gc() {
  char ret;
  while ((ret = getchar()) == ' ' || ret == '\n' || ret == '\t')
    ;
  return ret;
}
template <class T>
inline T sq(T x) {
  return x * x;
}
const int LIM = 3e5 + 10;
vector<pair<int, int> > edges;
vector<int> ans;
bool vis[LIM];
inline void init(int n) {
  for (int i = 1; i <= n * 3; i++) vis[i] = false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int t, n, m, u, v;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    init(n);
    edges.clear(), ans.clear();
    for (int i = 0; i < m; i++) {
      cin >> u >> v;
      edges.push_back(make_pair(u, v));
    }
    for (int i = 0; i < m; i++) {
      if (!vis[edges[i].first] && !vis[edges[i].second]) {
        ans.push_back(i + 1);
        vis[edges[i].first] = vis[edges[i].second] = true;
      }
    }
    if (ans.size() >= n) {
      printf("Matching\n");
      for (int i = 0; i < n; i++) {
        if (i) putchar(' ');
        printf("%d", ans[i]);
      }
    } else {
      printf("IndSet\n");
      bool flag = false;
      int cnt = 0;
      for (int i = 1; i <= n * 3; i++) {
        if (cnt == n) break;
        if (!vis[i]) {
          if (flag)
            putchar(' ');
          else
            flag = true;
          printf("%d", i);
          cnt++;
        }
      }
    }
    putchar('\n');
  }
  return 0;
}
