#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int T, N, M, u, v, matching[3 * MAXN];
vector<int> match;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> T;
  while (T--) {
    cin >> N >> M;
    for (int i = 1; i <= 3 * N; i++) matching[i] = 0;
    match.clear();
    for (int i = 0; i < M; i++) {
      cin >> u >> v;
      if (!matching[u] && !matching[v])
        matching[u] = 1, matching[v] = 1, match.push_back(i + 1);
    }
    if (match.size() >= N) {
      cout << "Matching\n";
      for (int i = 0; i < N; i++) cout << match[i] << " ";
      cout << "\n";
    } else {
      cout << "IndSet\n";
      int cnt = 0;
      for (int i = 1; i <= 3 * N; i++) {
        if (cnt == N) break;
        if (!matching[i]) cout << i << " ", cnt++;
      }
      cout << "\n";
    }
  }
  return 0;
}
