#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 23;
int n, m, vis[N];
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<int> IndSet, Matching;
    for (int i = 0, ggd = 3 * n + 1; i < ggd; i++) vis[i] = 0;
    for (int i = 1, ggd = m + 1; i < ggd; i++) {
      int x, y;
      cin >> x >> y;
      if (!vis[x] && !vis[y]) Matching.push_back(i), vis[x] = 1, vis[y] = 1;
    }
    for (int i = 1, ggd = 3 * n + 1; i < ggd; i++)
      if (!vis[i]) IndSet.push_back(i);
    if (((int)(IndSet).size()) >= n) {
      cout << "IndSet\n";
      for (int i = 0, ggd = n; i < ggd; i++) cout << IndSet[i] << " ";
      cout << "\n";
    } else {
      assert(((int)(Matching).size()) >= n);
      cout << "Matching\n";
      for (int i = 0, ggd = n; i < ggd; i++) cout << Matching[i] << " ";
      cout << "\n";
    }
  }
}
