#include <bits/stdc++.h>
using namespace std;
const long long maxn = 300100, maxv = 100, mod = 1e9 + 7, maxa = 1005,
                maxs = 820, maxb = 20, base = 737, base2 = 3079,
                mod3 = 998244353, delt = 10513;
const long long inf = 2e16;
const long long infint = 1e9 + 11;
long long max(long long x, long long y) { return (x > y ? x : y); }
long long min(long long x, long long y) { return (x < y ? x : y); }
bool vis[maxn];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long ts;
  cin >> ts;
  while (ts--) {
    long long n, m, x = 0;
    cin >> n >> m;
    vector<pair<long long, long long> > edg;
    for (long long i = 0; i < m; i++) {
      long long a, b;
      cin >> a >> b;
      a--;
      b--;
      edg.push_back(make_pair(a, b));
    }
    vector<long long> mtc;
    for (auto p : edg) {
      x++;
      if (!vis[p.first] && !vis[p.second]) {
        vis[p.first] = 1;
        vis[p.second] = 1;
        mtc.push_back(x);
      }
    }
    if (mtc.size() >= n) {
      for (long long i = 0; i < 3 * n; i++) {
        vis[i] = 0;
      }
      cout << "Matching" << endl;
      for (long long i = 0; i < n; i++) {
        cout << mtc[i] << ' ';
      }
      cout << endl;
      continue;
    }
    cout << "IndSet" << endl;
    long long nm = 0;
    for (long long i = 0; i < 3 * n; i++) {
      if (!vis[i] && nm < n) {
        cout << i + 1 << ' ';
        nm++;
      }
      vis[i] = 0;
    }
    cout << endl;
  }
  return 0;
}
