#include <bits/stdc++.h>
using namespace std;
long long MOD = int(1e9) + 7;
int debug = 1;
const int N = int(1e6) + 5;
using namespace std;
vector<int> nei[N];
vector<int> idx[N];
bool vis[N];
vector<int> edges;
vector<int> nodes;
int main() {
  int i, j, n, t, m;
  ios::sync_with_stdio(false);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (i = 0; i < 3 * n + 5; i++) {
      nei[i].clear();
      idx[i].clear();
      vis[i] = false;
    }
    edges.clear();
    nodes.clear();
    for (i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      nei[u].push_back(v);
      nei[v].push_back(u);
      idx[u].push_back(i + 1);
      idx[v].push_back(i + 1);
    }
    for (i = 1; i < 3 * n + 1; i++) {
      if (vis[i]) continue;
      int next_node_idx = -1;
      for (j = 0; j < nei[i].size(); j++) {
        if (!vis[nei[i][j]]) {
          next_node_idx = j;
          break;
        }
      }
      if (next_node_idx == -1)
        nodes.push_back(i);
      else {
        edges.push_back(idx[i][next_node_idx]);
        vis[nei[i][next_node_idx]] = true;
        vis[i] = true;
      }
    }
    if (nodes.size() >= n) {
      cout << "IndSet" << endl;
      for (i = 0; i < n; i++) cout << nodes[i] << " ";
    } else {
      cout << "Matching" << endl;
      for (i = 0; i < n; i++) cout << edges[i] << " ";
    }
    cout << endl;
  }
}
