#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 5;
struct Edge {
  int u, v, id;
};
vector<Edge> g[N];
int vis[N], used[N];
vector<int> matching;
void solve(int u) {
  vis[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    Edge e = g[u][i];
    if (!used[u] && !used[e.v]) {
      matching.emplace_back(e.id);
      used[u] = used[e.v] = 1;
    }
    if (!vis[e.v]) {
      solve(e.v);
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, u, v;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
      cin >> u >> v;
      Edge e1, e2;
      e1.u = u;
      e1.v = v;
      e1.id = i;
      e2.u = v;
      e2.v = u;
      e2.id = i;
      g[u].emplace_back(e1);
      g[v].emplace_back(e2);
    }
    for (int i = 1; i <= 3 * n; i++) {
      if (!vis[i]) solve(i);
    }
    if (matching.size() >= n) {
      cout << "Matching" << '\n';
      for (int i = 0; i < n; i++) {
        cout << matching[i] << " ";
      }
      cout << '\n';
    } else {
      cout << "IndSet" << '\n';
      for (int i = 1, cnt = 0; i <= 3 * n && cnt < n; i++) {
        if (!used[i]) {
          cout << i << " ";
          cnt++;
        }
      }
      cout << '\n';
    }
    for (int i = 1; i <= 3 * n; i++) g[i].clear();
    for (int i = 1; i <= 3 * n; i++) {
      used[i] = vis[i] = 0;
    }
    matching.clear();
  }
  return 0;
}
