#include <bits/stdc++.h>
using namespace std;
long long int binpowmod(long long int a, long long int b, long long int m) {
  a %= m;
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long int binpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return binpowmod(n, p - 2, p);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t, m, n, i, u, v, f = 0, j, ans = 0, k, x, r;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    set<long long int> s, q;
    vector<long long int> matching;
    for (i = 0; i < m; ++i) {
      cin >> u >> v;
      if (s.find(u) == s.end() && s.find(v) == s.end()) {
        s.insert(u);
        s.insert(v);
        matching.push_back(i + 1);
      } else {
        if (s.find(u) == s.end()) q.insert(u);
        if (s.find(v) == s.end()) q.insert(v);
      }
    }
    if (matching.size() >= n) {
      cout << "Matching" << endl;
      for (i = 0; i < n; ++i) cout << matching[i] << " ";
    } else {
      cout << "Indset" << endl;
      j = 0;
      for (auto it : q) {
        if (j == n) break;
        cout << it << " ";
        j++;
      }
    }
    cout << endl;
  }
  return 0;
}
