#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 300500;
const long long INF = 0x3f3f3f3f;
const long long LINF = 0x1f3f3f3f3f3f3f3f;
const long long MOD = 998244353;
const long long OVER_FLOW = 0xffffffff;
long long n;
vector<pair<long long, long long>> edges;
vector<long long> res;
bool vis[MAXN];
int main() {
  ios::sync_with_stdio(false);
  long long T;
  cin >> T;
  while (T--) {
    edges.clear(), res.clear();
    long long cnt = 0, m;
    cin >> n >> m;
    for (long long i = 1; i <= 3 * n; i++) vis[i] = false;
    for (long long i = 1; i <= m; i++) {
      long long u, v;
      cin >> u >> v;
      edges.emplace_back(u, v);
    }
    for (long long i = 0; i < edges.size(); i++) {
      if (!vis[edges[i].first] && !vis[edges[i].second]) {
        vis[edges[i].first] = vis[edges[i].second] = true;
        cnt += 2;
        res.push_back(i + 1);
      }
    }
    if (res.size() >= n) {
      cout << "Matching" << '\n';
      for (auto it : res) {
        cout << it << " ";
      }
      cout << '\n';
    } else {
      cout << "IndSet" << '\n';
      for (long long i = 1; i <= 3 * n; i++) {
        if (!vis[i]) cout << i << " ";
      }
      cout << '\n';
    }
  }
  return 0;
}
