#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> ck(3 * n + 1, 0), ans;
    ans.clear();
    for (int i = 0; i < m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      if (!ck[x] && !ck[y]) {
        ck[x] = ck[y] = 1;
        ans.push_back(i + 1);
      }
    }
    if (ans.size() >= n) {
      printf("Matching\n");
      for (int i = 0; i < n; i++) printf("%d ", ans[i]);
      printf("\n");
    } else {
      printf("IndSet\n");
      for (int i = 1, j = 0; i <= 3 * n && j < n; i++) {
        if (!ck[i]) {
          printf("%d ", i);
          ++j;
        }
      }
      printf("\n");
    }
  }
  return 0;
}
