#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
int t;
vector<vector<int>> g;
vector<bool> used;
vector<int> match;
int main() {
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    g.assign(3 * n + 1, vector<int>());
    used.assign(3 * n + 1, false);
    match.clear();
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
      if (!used[u] && !used[v]) {
        match.push_back(i + 1);
        used[u] = true;
        used[v] = true;
      }
    }
    if (match.size() >= n) {
      cout << "Matching\n";
      for (size_t i = 0; i < match.size() && n > 0; ++i, --n) {
        cout << match[i] << ' ';
      }
    } else {
      cout << "IndSet\n";
      int k = n;
      for (int v = 1; v <= 3 * n && k > 0; ++v) {
        if (!used[v]) {
          cout << v << ' ';
          --k;
        }
      }
    }
    cout << '\n';
  }
  return 0;
}
