#include <bits/stdc++.h>
using namespace std;
int t;
vector<vector<int>> grap;
vector<pair<int, int>> ve;
vector<int> used, used2, ide;
bool opt(int a, int b) {
  return grap[ve[a].first].size() + grap[ve[a].second].size() <
         grap[ve[b].first].size() + grap[ve[b].second].size();
}
bool opt2(int a, int b) { return grap[a].size() < grap[b].size(); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, m;
    cin >> n >> m;
    grap.clear();
    ve.clear();
    used.clear();
    used2.clear();
    ide.clear();
    used.resize(3 * n + 1);
    used2.resize(3 * n + 1);
    grap.resize(3 * n + 1);
    ve.resize(m);
    for (int i = 0; i < m; i++) {
      cin >> ve[i].first >> ve[i].second;
      grap[ve[i].first].push_back(ve[i].second);
      grap[ve[i].second].push_back(ve[i].first);
      ide.push_back(i);
    }
    sort(ide.begin(), ide.end(), opt);
    vector<int> ans1;
    for (int i = 0; i < m; i++)
      if (used[ve[ide[i]].first] == 0 && used[ve[ide[i]].second] == 0)
        ans1.push_back(ide[i]),
            used[ve[ide[i]].first] = used[ve[ide[i]].second] = 1;
    if (ans1.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) cout << ans1[i] + 1 << " ";
      cout << "\n";
      continue;
    }
    vector<int> vv, ans2;
    for (int i = 0; i < 3 * n; i++) vv.push_back(i + 1);
    sort(vv.begin(), vv.end(), opt2);
    for (int i = 0; i < 3 * n; i++)
      if (used2[vv[i]] == 0) {
        ans2.push_back(vv[i]);
        used2[vv[i]] = 1;
        for (int j = 0; j < grap[vv[i]].size(); j++) used2[grap[vv[i]][j]] = 1;
      }
    if (ans2.size() >= n) {
      cout << "IndSet\n";
      for (int i = 0; i < n; i++) cout << ans2[i] << " ";
      cout << "\n";
      continue;
    }
    cout << "Impossible\n";
  }
  return 0;
}
