#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int lmt = n;
  n *= 3;
  bool covered[n];
  memset(covered, false, sizeof(covered));
  vector<int> match;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    if (match.size() < lmt && !covered[u] && !covered[v]) {
      match.push_back(i);
      covered[u] = true;
      covered[v] = true;
    }
  }
  if (match.size() == lmt) {
    cout << "Matching\n";
    for (int x : match) cout << x << " ";
    cout << "\n";
    return;
  }
  vector<int> idp;
  for (int i = 0; i < n && idp.size() < lmt; ++i)
    if (!covered[i]) idp.push_back(i + 1);
  cout << "IndSet\n";
  for (int x : idp) cout << x << " ";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
