#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long double PI = acos(-1.0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int T;
  cin >> T;
  while (T--) {
    long long int n, m;
    cin >> n >> m;
    vector<long long int> ver(3 * n + 1, 0);
    vector<pair<long long int, long long int>> edge(m);
    for (long long int i = 0; i < m; i++) {
      cin >> edge[i].first;
      cin >> edge[i].second;
    }
    vector<long long int> ans1;
    for (long long int i = 0; i < m; i++) {
      if (ver[edge[i].first] == 0 && ver[edge[i].second] == 0) {
        ans1.push_back(i + 1);
        ver[edge[i].first] = 1;
        ver[edge[i].second] = 1;
      }
      if (ans1.size() == n) break;
    }
    if (ans1.size() == n) {
      cout << "Matching" << '\n';
      for (auto i : ans1) cout << i << " ";
      cout << '\n';
    } else {
      cout << "IndSet" << '\n';
      long long int done = 0;
      for (long long int i = 1; i < 3 * n + 1; i++) {
        if (ver[i] == 0) {
          done++;
          cout << i << " ";
        }
        if (done == n) break;
      }
      cout << '\n';
    }
  }
  return 0;
}
