#include <bits/stdc++.h>
long double PI = 3.141592653589793238462643383279502884197;
using namespace std;
vector<pair<int, int> > vec;
vector<int> ans;
bool use[300001];
int main() {
  int t, n, m, a, b;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &n, &m);
    vec.clear();
    ans.clear();
    for (int i = 1; i <= 3 * n; i++) use[i] = false;
    for (int i = 0; i < m; i++) {
      scanf("%d %d", &a, &b);
      vec.push_back({a, b});
    }
    int cnt = 0, sz = vec.size();
    for (int i = 0; i < sz; i++) {
      pair<int, int> v = vec[i];
      if (!use[v.first] && !use[v.second]) {
        cnt++;
        ans.push_back(i + 1);
        use[v.first] = use[v.second] = true;
      }
      if (cnt == n) break;
    }
    if (cnt == n) {
      printf("Matching\n");
      for (int v : ans) printf("%d ", v);
    } else {
      printf("IndSet\n");
      cnt = 0;
      for (int i = 1; i <= 3 * n; i++) {
        if (!use[i]) {
          printf("%d ", i);
          cnt++;
        }
        if (cnt == n) break;
      }
    }
    printf("\n");
  }
  return 0;
}
