#include <bits/stdc++.h>
using namespace std;
double START_TIME;
void exit() { exit(0); }
template <typename A, typename B>
ostream& operator<<(ostream& os, pair<A, B> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (int i = 0; i <= (int)v.size() - 1; i++) {
    os << v[i] << " ";
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> t) {
  for (auto z : t) {
    os << z << " ";
  }
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, map<T1, T2> t) {
  cerr << endl;
  for (auto z : t) {
    os << "\t" << z.first << " -> " << z.second << endl;
  }
  return os;
}
const int MAX = 5e5 + 41;
int n, m;
int u[MAX];
vector<int> ans;
vector<pair<int, int> > e;
void clear() {
  ans.clear();
  e.clear();
  fill_n(&u[0], n * 3, 0);
}
void solve() {
  for (int i = 0; i <= (int)e.size() - 1; i++) {
    auto z = e[i];
    int x = z.first;
    int y = z.second;
    if (u[x] || u[y]) continue;
    u[x] = u[y] = 1;
    ans.push_back(i);
  }
  if ((int)ans.size() > n) ans.resize(n);
  if ((int)ans.size() == n) {
    printf("Matching\n");
    for (int x : ans) {
      printf("%d ", x + 1);
    }
  } else {
    printf("IndSet\n");
    int q = 0;
    for (int i = 0; i <= n * 3 - 1; i++) {
      if (u[i]) continue;
      printf("%d ", i + 1);
      q++;
      if (q == n) break;
    }
  }
  printf("\n");
  clear();
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      x--, y--;
      e.push_back(make_pair(x, y));
    }
    solve();
  }
  exit();
  return 0;
}
