#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 1000000007;
const long long inf = 3e18;
const double eps = 0.0000001;
long long T;
long long n, m;
unordered_map<int, unordered_map<int, int>> g;
unordered_set<int> e;
unordered_set<int> v;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  cin >> T;
  for (long long _T = (0); _T < (T); ++_T) {
    cin >> n >> m;
    g.clear();
    e.clear();
    v.clear();
    for (long long i = (0); i < (m); ++i) {
      long long u, v;
      cin >> u >> v;
      u--;
      v--;
      g[u][v] = i;
      g[v][u] = i;
    }
    for (long long i = (0); i < (3 * n); ++i) {
      for (auto& vm : g[i]) {
        if (v.find(vm.first) != v.end()) {
          e.insert(vm.second);
          v.erase(vm.first);
          goto outer;
        }
      }
      v.insert(i);
    outer:;
    }
    if (((int)(v).size()) >= n) {
      cout << "IndSet\n";
      long long k = 0;
      for (auto& i : v) {
        cout << (i + 1) << " \n"[k == n - 1];
        if (k == n - 1) break;
        k++;
      }
    } else if (((int)(e).size()) >= n) {
      cout << "Matching\n";
      long long k = 0;
      for (auto& i : e) {
        cout << (i + 1) << " \n"[k == n - 1];
        if (k == n - 1) break;
        k++;
      }
    } else {
      cout << "Impossible\n";
    }
  }
  return 0;
}
