#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
const int M = 22;
const int mod = 1e9 + 7;
void solve1() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int> > > v(3 * n + 1);
  vector<bool> used(3 * n + 1, false);
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back({y, i});
    v[y].push_back({x, i});
  }
  vector<int> ans;
  for (int i = 1; i <= n + n + n; i++) {
    if (used[i]) continue;
    for (auto x : v[i]) {
      if (!used[x.first]) {
        ans.push_back(x.second);
        used[x.first] = used[i] = true;
        break;
      }
    }
  }
  if ((int)ans.size() >= n) {
    cout << "Matching\n";
    for (int i = 0; i < n; i++) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  } else {
    cout << "IndSet\n";
    ans.clear();
    for (int i = 1; i <= n * 3; i++) {
      if (!used[i]) {
        ans.push_back(i);
      }
    }
    for (int i = 0; i < n; i++) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  int cghf = 1;
  cin >> cghf;
  while (cghf--) {
    solve1();
  }
}
