#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 2;
int visit[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= 3 * n; ++i) visit[i] = 0;
    vector<int> edges;
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      if (!visit[u] && !visit[v]) {
        visit[u] = visit[v] = true;
        edges.push_back(i + 1);
      }
    }
    if (edges.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; ++i) cout << edges[i] << ' ';
    } else {
      int cnt = n;
      cout << "IndSet\n";
      for (int i = 1; i <= 3 * n; ++i) {
        if (cnt && !visit[i]) {
          cout << i << ' ';
          cnt--;
        }
      }
    }
    cout << '\n';
  }
}
