#include <bits/stdc++.h>
using namespace std;
void preprocess(void) { return; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<int> vis(3 * n + 1);
    vector<int> mat;
    for (auto i = (0); i < m; i++) {
      int u, v;
      cin >> u >> v;
      if (!vis[u] && !vis[v]) {
        vis[u] = vis[v] = 1;
        mat.push_back(i + 1);
      }
    }
    if ((int)(mat).size() >= n) {
      cout << "Matching" << endl;
      for (auto i = (0); i < n; i++) cout << mat[i] << " ";
    } else {
      cout << "IndSet" << endl;
      int cnt = 0;
      for (auto i = (1); i < 3 * n + 1; i++) {
        if (!vis[i]) cout << i << " ", cnt++;
        if (cnt == n) break;
      }
    }
    cout << endl;
  }
}
