#include <bits/stdc++.h>
using namespace std;
const int LIMN = 3e5 + 10;
vector<int> matched;
int match[LIMN];
int N, M;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int qtt;
  cin >> qtt;
  while (qtt--) {
    cin >> N >> M;
    matched.clear();
    for (int i = 1; i <= 3 * N; i++) match[i] = 0;
    for (int i = 1, a, b; i <= M; i++) {
      cin >> a >> b;
      if (!match[a] && !match[b]) {
        match[a] = b;
        match[b] = a;
        matched.push_back(i);
      }
    }
    if (matched.size() >= N) {
      cout << "Matching\n";
      for (int i = 0; i < N; i++) cout << matched[i] << ' ';
      cout << '\n';
    } else {
      cout << "IndSet\n";
      int qt = N;
      for (int i = 1; qt && i <= 3 * N; i++) {
        if (!match[i]) {
          cout << i << ' ';
          qt--;
        }
      }
      cout << '\n';
    }
  }
  return 0;
}
