#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e18;
const long long mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void print(long long a[], long long n) {
  for (long long i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
}
long long power(long long x, long long y) {
  if (y <= 0) return 1;
  long long ans = 1;
  x %= mod;
  while (y) {
    if (y & 1) ans = (x * ans) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return ans;
}
long long modInverse(long long n) { return power(n, mod - 2); }
inline long long mul(long long a, long long b) { return (a * b) % mod; }
inline long long sub(long long a, long long b) {
  long long c = (a - b);
  if (c < 0) c += mod;
  return c;
}
inline long long add(long long a, long long b) {
  long long c = (a + b);
  if (c >= mod) c -= mod;
  return c;
}
inline long long divi(long long a, long long b) {
  return mul(a, modInverse(b));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(10);
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    map<long long, long long> mp;
    vector<pair<long long, long long> > edges;
    vector<long long> ans;
    for (int i = 0; i < m; i++) {
      long long u, v;
      cin >> u >> v;
      edges.push_back({u, v});
      if (mp[u] == 0 && mp[v] == 0) {
        ans.push_back(i + 1);
        mp[u] = 1;
        mp[v] = 1;
      }
    }
    if (ans.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
      }
      cout << "\n";
    } else {
      cout << "IndSet\n";
      int c = 0;
      for (int i = 1; i <= 3 * n; i++) {
        if (mp[i] == 0) {
          cout << i << " ";
          c++;
        }
        if (c == n) break;
      }
      cout << "\n";
    }
  }
  return 0;
}
