#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 1;
bool dead[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    int mx = 3 * n;
    for (int i = 0; i < mx + 2; i++) dead[i] = 0;
    vector<pair<int, int>> g[mx];
    vector<int> ans1;
    vector<int> ans2;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      g[x].push_back({y, i});
      g[y].push_back({x, i});
    }
    for (int i = 0; i < mx; i++) {
      if (dead[i]) {
        continue;
      }
      int s = g[i].size();
      dead[i] = 1;
      int reals = 0;
      for (auto j : g[i]) {
        if (dead[j.first] == 0) {
          reals++;
        }
      }
      if (reals == 0) {
        ans1.push_back(i);
        continue;
      }
      for (int j = 0; j < s; j++) {
        int y = g[i][j].first;
        if (!dead[y]) {
          dead[y] = 1;
          ans2.push_back(g[i][j].second);
          break;
        }
      }
    }
    if (ans1.size() >= n) {
      cout << "IndSet\n";
      for (int i = 0; i < n; i++) {
        cout << ans1[i] + 1 << " ";
      }
      cout << "\n";
      continue;
    }
    if (ans2.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) {
        cout << ans2[i] + 1 << " ";
      }
      cout << "\n";
      continue;
    }
  }
  return 0;
}
