#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, from, ind;
};
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  for (int w = 0; w < T; w++) {
    int n, m;
    cin >> n >> m;
    n = n;
    vector<edge> e(m);
    for (int i = 0; i < m; i++) {
      cin >> e[i].to >> e[i].from;
      e[i].to--;
      e[i].from--;
      e[i].ind = i;
    }
    vector<int> us(3 * n, 0);
    vector<int> u(m, 0);
    for (int i = 0; i < m; i++) {
      if (us[e[i].to] == 0 && us[e[i].from] == 0) {
        us[e[i].to] = 1;
        us[e[i].from] = 1;
        u[e[i].ind] = 1;
      }
    }
    int cnt = 0;
    for (int i = 0; i < m; i++) {
      if (u[i]) cnt++;
    }
    if (cnt >= n) {
      cout << "Matching" << endl;
      int cn = 0;
      for (int i = 0; i < m; i++) {
        if (u[i]) {
          cn++;
          cout << e[i].ind + 1 << " ";
        }
        if (cn == n) break;
      }
    } else {
      cout << "IndSet" << endl;
      int cn = 0;
      for (int i = 0; i < 3 * n; i++) {
        if (!us[i]) {
          cn++;
          cout << i + 1 << " ";
        }
        if (cn == n) break;
      }
    }
    cout << endl;
  }
  return 0;
}
