#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> vis(3 * n + 1, 0);
  vector<int> ans, v;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (vis[u] or vis[v]) continue;
    ans.push_back(i + 1);
    vis[u] = vis[v] = 1;
  }
  if (ans.size() >= n) {
    ans.resize(n);
    cout << "Matching\n";
    for (int x : ans) cout << x << " ";
    return;
  }
  cout << "IndSet\n";
  for (int i = 1; i <= 3 * n; i++)
    if (!vis[i]) v.push_back(i);
  v.resize(n);
  for (int x : v) cout << x << " ";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    solve();
    cout << "\n";
  }
}
