#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
vector<pair<long long, long long>> vc[300001];
vector<pair<long long, long long>> vv;
long long vst[300001];
int32_t main() {
  fastio();
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vv.clear();
    for (long long i = 0; i < 3 * n + 1; i++) vc[i].clear();
    for (long long i = 0; i < 3 * n + 1; i++) vst[i] = 0;
    for (long long i = 0; i < m; i++) {
      long long u, v;
      cin >> u >> v;
      vc[u].push_back(make_pair(v, i + 1));
      vc[v].push_back(make_pair(u, i + 1));
    }
    for (long long i = 1; i < 3 * n + 1; i++) {
      vv.push_back(make_pair(vc[i].size(), i));
    }
    sort(vv.begin(), vv.end());
    vector<long long> ans;
    for (long long i = 0; i < vv.size(); i++) {
      if (!vst[vv[i].second]) {
        long long fg = 0;
        for (auto j : vc[vv[i].second]) {
          if (vst[j.first] == 1) {
            fg = 1;
            break;
          }
        }
        if (fg == 0) {
          vst[vv[i].second] = 1;
          ans.push_back(vv[i].second);
        }
      }
    }
    if (ans.size() >= n) {
      cout << "IndSet"
           << "\n";
      for (long long i = 0; i < n; i++) cout << ans[i] << " ";
      cout << "\n";
      continue;
    }
    ans.clear();
    for (long long i = 0; i < 3 * n + 1; i++) vst[i] = 0;
    for (long long i = 0; i < vv.size(); i++) {
      if (vst[vv[i].second] == 0 && vc[vv[i].second].size() != 0) {
        long long mn = 1e9, id = -1, i2;
        for (auto j : vc[vv[i].second]) {
          if (vst[j.first] == 0) {
            if (mn > vc[j.first].size()) {
              mn = vc[j.first].size();
              id = j.second;
              i2 = j.first;
            }
          }
        }
        if (id != -1) {
          ans.push_back(id);
          vst[vv[i].second] = 1;
          vst[i2] = 1;
        }
      }
    }
    if (ans.size() >= n) {
      cout << "Matching"
           << "\n";
      for (long long i = 0; i < n; i++) cout << ans[i] << " ";
      cout << "\n";
      continue;
    }
    cout << "Impossible"
         << "\n";
  }
  return 0;
}
