#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
template <typename A, typename B>
ostream& operator<<(ostream& os, pair<A, B> p) {
  return os << '{' << p.first << ", " << p.second << '}';
}
template <typename A, typename B>
istream& operator>>(istream& is, pair<A, B>& p) {
  return is >> p.first >> p.second;
}
const int oo = 0x3f3f3f3f;
const ll OO = ll(oo) * oo;
const int N = 300005;
void solve() {
  bitset<N> seen;
  int n, m;
  cin >> n >> m;
  int nn = 3 * n;
  vi matching;
  for (int i = 1; i < m + 1; i++) {
    int u, v;
    cin >> u >> v;
    if (!seen[u] && !seen[v]) {
      seen[u] = true;
      seen[v] = true;
      matching.emplace_back(i);
    }
  }
  if (int((matching).size()) >= n) {
    cout << "Matching" << '\n';
    for (int i = 0; i < n; i++) cout << matching[i] << ' ';
    cout << '\n';
    return;
  }
  int c = 0;
  cout << "IndSet" << '\n';
  for (int i = 1; i < nn + 1 && c < n; i++) {
    if (!seen[i]) {
      cout << i << ' ';
      c++;
    }
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  while (n--) solve();
  return 0;
}
