#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, m;
    cin >> n >> m;
    unordered_map<int, int> used;
    vector<int> order(n * 3, 0);
    vector<int> matching;
    vector<pair<int, int>> edge;
    for (int j = 0; j < m; j++) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      edge.push_back(pair<int, int>{u, v});
    }
    for (int j = 0; j < m; j++) {
      order[edge[j].first]++;
      order[edge[j].second]++;
      if (used[edge[j].first] == 0 && used[edge[j].second] == 0) {
        matching.push_back(j + 1);
        used[edge[j].first]++;
        used[edge[j].second]++;
      }
    }
    if ((int)matching.size() >= n) {
      cout << "Matching" << endl;
      for (int j = 0; j < n; j++) {
        cout << matching[j] << " ";
      }
      cout << endl;
      continue;
    } else {
      cout << "IndSet" << endl;
      vector<int> indset;
      for (int j = 0; j < 3 * n; j++) {
        if (order[j] == 0) {
          indset.push_back(j + 1);
        }
      }
      for (auto& v : edge) {
        if (order[v.first] == 1) {
          indset.push_back(v.first + 1);
        } else if (order[v.second] == 1) {
          indset.push_back(v.second + 1);
        }
      }
      for (int j = 0; j < min(n, (int)indset.size()); j++) {
        cout << indset[j] << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
