#include <bits/stdc++.h>
using namespace std;
const long long N = 5e6 + 30, Mod = 1e9 + 7;
const long long SQ = 330;
pair<long long, long long> E[N];
long long use[N];
vector<long long> G[N];
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> match;
  for (int i = 1; i <= m; i++) {
    long long v, u;
    cin >> v >> u;
    E[i] = {v, u};
    G[v].push_back(u);
    G[u].push_back(v);
    if (use[v] || use[u] || match.size() == n) continue;
    use[v] = 1;
    use[u] = 1;
    match.push_back(i);
  }
  if (match.size() >= n) {
    cout << "Matching\n";
    for (auto u : match) cout << u << ' ';
    cout << '\n';
  } else {
    vector<long long> vec;
    for (int i = 1; i <= 3 * n; i++) {
      if (vec.size() == n) break;
      if (!use[i]) vec.push_back(i);
    }
    cout << "IndSet\n";
    for (auto u : vec) cout << u << ' ';
    cout << '\n';
  }
  for (int i = 1; i <= 3 * n; i++) G[i].clear(), use[i] = 0;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  long long q;
  cin >> q;
  while (q--) solve();
  return (0);
}
