#include <bits/stdc++.h>
using namespace std;
const long long MAXVAL = (long long)1e18 + 1;
const long long MOD = 1000000007ll;
const int INF = 1000000001;
long long poww(int x, long long pow) {
  if (pow == 0ll) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x) % MOD;
  }
  return ans % MOD;
}
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}
long long sq(int x, int y) { return x * 1ll * x + y * 1ll * y; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  cin >> q;
  while (q-- > 0) {
    int nn;
    cin >> nn;
    int n = 3 * nn;
    int m;
    cin >> m;
    vector<vector<pair<int, int>>> gr(n);
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      --u;
      --v;
      gr[u].emplace_back(v, i);
      gr[v].emplace_back(u, i);
    }
    vector<pair<int, int>> match;
    vector<int> iso;
    vector<bool> done(n, false);
    vector<bool> matchset(n, false);
    for (int i = 0; i < n; ++i) {
      if (done[i]) continue;
      for (auto nextp : gr[i]) {
        int next = nextp.first;
        if (!matchset[next]) {
          matchset[i] = true;
          matchset[next] = true;
          match.push_back(nextp);
          done[i] = true;
          done[next] = true;
          break;
        }
      }
      if (done[i]) continue;
      done[i] = true;
      iso.push_back(i);
    }
    if (iso.size() >= nn) {
      cout << "IndSet\n";
      for (int i = 0; i < nn; ++i) {
        cout << iso[i] + 1 << " ";
      }
      cout << "\n";
    } else {
      assert(match.size() >= nn);
      cout << "Matching\n";
      for (int i = 0; i < nn; ++i) {
        cout << match[i].second + 1 << " ";
      }
      cout << "\n";
    }
  }
  return 0;
}
