#include <bits/stdc++.h>
using namespace std;
void findRandomMatching(int pos, vector<int>& vis, vector<int>& matching,
                        const vector<vector<pair<int, int>>>& conns) {
  for (auto [p, i] : conns[pos]) {
    if (vis[pos] == 0 && vis[p] <= 0) {
      matching.push_back(i);
      bool cont = vis[p] < 0;
      vis[pos] = vis[p] = 1;
      if (cont) findRandomMatching(p, vis, matching, conns);
    } else if (vis[p] < 0) {
      vis[p] = 0;
      findRandomMatching(p, vis, matching, conns);
    }
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> conns(3 * n);
  vector<pair<int, int>> edges;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edges.emplace_back(a, b);
    conns[a].emplace_back(b, i);
    conns[b].emplace_back(a, i);
  }
  vector<int> matching, vis(3 * n, -1);
  for (int i = 0; i < conns.size(); i++) {
    if (vis[i] < 0) findRandomMatching(i, vis, matching, conns);
  }
  if (matching.size() >= n) {
    cout << "Matching\n";
    for (int i = 0; i < n; i++) {
      cout << matching[i] + 1 << " ";
    }
  } else {
    vector<bool> avail(conns.size(), 1);
    for (int e : matching) {
      avail[edges[e].first] = 0;
      avail[edges[e].second] = 0;
    }
    cout << "IndSet\n";
    int out = 0;
    for (int i = 0; i < conns.size() && out < n; i++) {
      if (avail[i]) {
        out++;
        cout << i + 1 << " ";
      }
    }
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    solve();
  }
}
