#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    int V[m], U[m];
    vector<int> adj[3 * n];
    unordered_set<int> S;
    vector<int> ans;
    unordered_set<int> W;
    for (int i = 0; i < m; i++) {
      cin >> V[i] >> U[i];
      V[i]--;
      U[i]--;
      adj[V[i]].push_back(i);
      adj[U[i]].push_back(i);
    }
    for (int i = 0; i < n; i++) {
      W.insert(i);
      for (auto e : adj[i]) {
        if ((V[e] ^ U[e] ^ i) < n) S.insert(e);
      }
    }
    bool f = 0;
    for (int i = 0; i < n; i++) {
      if (S.empty()) {
        cout << "IndSet\n";
        for (auto v : W) {
          cout << v + 1 << ' ';
        }
        cout << '\n';
        f = 1;
        break;
      }
      int e = *S.begin();
      ans.push_back(e);
      W.erase(V[e]);
      W.erase(U[e]);
      for (auto t : adj[V[e]]) S.erase(t);
      for (auto t : adj[U[e]]) S.erase(t);
      W.insert(n + 2 * i);
      W.insert(n + 2 * i + 1);
      for (auto e : adj[n + 2 * i]) {
        if (W.find((n + 2 * i) ^ V[e] ^ U[e]) != W.end()) S.insert(e);
      }
      for (auto e : adj[n + 2 * i + 1]) {
        if (W.find((n + 2 * i + 1) ^ V[e] ^ U[e]) != W.end()) S.insert(e);
      }
    }
    if (!f) {
      cout << "Matching\n";
      for (auto t : ans) {
        cout << t + 1 << ' ';
      }
      cout << '\n';
    }
  }
}
