#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int n, m, cnt = 0;
    cin >> n >> m;
    vector<pair<int, int>> edges;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      edges.push_back({x - 1, y - 1});
    }
    vector<int> ans, check(3 * n, 0);
    for (int i = 0; i < m; i++) {
      if (!check[edges[i].first] && !check[edges[i].second]) {
        cnt++;
        check[edges[i].first] = 1;
        check[edges[i].second] = 1;
        ans.push_back(i + 1);
      }
    }
    if (cnt >= n) {
      cout << "Matching" << endl;
      for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
      }
      cout << endl;
    } else {
      cout << "IndSet" << endl;
      int s = 0, i = 0;
      while (s < n) {
        if (!check[i]) {
          s++;
          cout << i + 1 << " ";
        }
        i++;
      }
      cout << endl;
    }
  }
}
