#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 2;
struct DS {
  vector<int> p, r, cmp;
  void init(int N) {
    p.assign(N, 0);
    r.assign(N, 0);
    cmp.assign(N, 1);
    for (int i = 0; i < int(N); i++) p[i] = i;
  }
  int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
  bool join(int a, int b) {
    int x = find(a), y = find(b);
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    p[x] = y;
    cmp[y] += cmp[x];
    if (r[x] == r[y]) r[y]++;
    return true;
  }
};
DS UF;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  int t;
  cin >> t;
  for (int o = 0; o < int(t); o++) {
    int n, m;
    cin >> n >> m;
    UF.init(3 * n + 5);
    vector<int> matching, indSet;
    for (int i = 0; i < int(m); i++) {
      int u, v;
      cin >> u >> v;
      u--, v--;
      int id1 = UF.find(u), id2 = UF.find(v);
      if (UF.cmp[id1] + UF.cmp[id2] <= 2)
        UF.join(id1, id2), matching.push_back(i);
    }
    for (int i = 0; i < int(3 * n); i++)
      if (UF.cmp[UF.find(i)] == 1) indSet.push_back(i);
    if ((int)indSet.size() >= n) {
      cout << "IndSet\n";
      for (int i = 0; i < int(n); i++) cout << indSet[i] + 1 << ' ';
    } else {
      cout << "Matching\n";
      for (int i = 0; i < int(n); i++) cout << matching[i] + 1 << ' ';
    }
    cout << '\n';
  }
  return 0;
}
