#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const int MAX_N = 1000011;
const long long INF = (1 << 29) + 123;
const long long MOD = 1000000007;
const long double PI = 4 * atan((long double)1);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, u, v;
    cin >> n >> m;
    vector<pair<int, int> > edges;
    for (int i = 0; i < m; i++) {
      cin >> u >> v;
      edges.push_back({u, v});
    }
    int vis[3 * n + 1];
    memset(vis, 0, sizeof vis);
    vector<int> matching;
    for (int i = 0; i < m; i++) {
      if (!vis[edges[i].first] && !vis[edges[i].second]) {
        matching.push_back(i + 1);
        vis[edges[i].first] = vis[edges[i].second] = 1;
      }
    }
    if ((int)matching.size() >= n) {
      cout << "Matching" << nl;
      for (int i = 0; i < n; i++) cout << matching[i] << " ";
      cout << nl;
    } else {
      cout << "IndSet" << nl;
      int c = 0;
      for (int i = 1; i < 3 * n; i++) {
        if (c == n) break;
        if (!vis[i]) cout << i << " ", c++;
      }
      cout << nl;
    }
  }
  return 0;
}
