#include <bits/stdc++.h>
using namespace std;
bool used[300000] = {};
vector<int> matching;
int T = 0, n = 0, m = 0;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> T;
  for (int t = 0; t < T; t++) {
    cin >> n >> m;
    for (int i = 0; i < 3 * n; i++) used[i] = false;
    matching.clear();
    for (int i = 0; i < m; i++) {
      int u = 0, v = 0;
      cin >> u >> v;
      u--;
      v--;
      if (!used[u] && !used[v]) {
        used[u] = used[v] = true;
        matching.push_back(i);
      }
    }
    int cnt = 0;
    for (int i = 0; i < 3 * n; i++)
      if (!used[i]) cnt++;
    if (cnt >= n) {
      cout << "IndSet\n";
      int j = 0;
      for (int i = 0; i < 3 * n; i++) {
        if (j < n && !used[i]) {
          cout << i + 1 << ' ';
          j++;
        }
      }
    } else {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) cout << matching[i] + 1 << ' ';
    }
    cout << "\n";
  }
  return 0;
}
