#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main() {
  int T;
  cin >> T;
  vector<pair<int, int>> edges;
  vector<int> matching;
  vector<bool> used;
  while (T--) {
    int n, m;
    scanf("%d %d", &n, &m);
    matching.clear();
    edges.clear();
    edges.resize(m);
    used.clear();
    used.resize(3 * n + 1);
    for (int i = 0; i < m; ++i) {
      scanf("%d %d", &edges[i].first, &edges[i].second);
      if (not used[edges[i].first] and not used[edges[i].second]) {
        matching.push_back(i + 1);
        used[edges[i].first] = true;
        used[edges[i].second] = true;
      }
    }
    if (matching.size() >= n) {
      printf("Matching\n");
      for (int i = 0; i < n; ++i) {
        if (i) printf(" ");
        printf("%d", matching[i]);
      }
      printf("\n");
    } else {
      printf("IndSet\n");
      int count = 0;
      for (int i = 1; i < 3 * n + 1 and count < n; ++i) {
        if (not used[i]) {
          if (count) printf(" ");
          printf("%d", i);
          ++count;
        }
      }
      printf("\n");
    }
  }
  return 0;
}
