#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using std::cin;
using std::cout;
using std::endl;
using std::list;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::multiset;
using std::pair;
using std::queue;
using std::set;
using std::sort;
using std::stack;
using std::string;
using std::swap;
using std::vector;
const double eps = 1e-6;
inline long long pow(long long a, long long b, long long p) {
  long long rtn = 1;
  while (b) {
    if (b & 1) rtn = rtn * a % p;
    a = a * a % p;
    b >>= 1;
  }
  return rtn;
}
long long inv(long long a, long long p) { return pow(a, p - 2, p); }
long long gcd(long long a, long long b) {
  long long k;
  while (b != 0) {
    k = b;
    b = a % b;
    a = k;
  }
  return a;
}
void makedata() {
  freopen("input.txt", "w", stdout);
  cout << "50 20" << endl;
  for (int i = (1); i <= (50); i++) cout << 592183311 + i << endl;
  fclose(stdout);
}
void TLE() {
  for (unsigned long long i = 0; i >= 0; i++) {
    if (i % 8475354556 == 0) cout << i << endl;
  }
}
void MLE(string s = "") { MLE(s + ' '); }
vector<int> G[330000];
bool f[550000], g[550000];
pair<int, int> edge[550000];
int main() {
  std::ios::sync_with_stdio(0), cin.tie(0);
  int q, n, m, x, y, p;
  cin >> q;
  while (q--) {
    cin >> n >> m;
    for (int i = (1); i <= (3 * n); i++) G[i].clear();
    for (int i = (1); i <= (m); i++) {
      cin >> x >> y;
      G[x].push_back(i);
      G[y].push_back(i);
      edge[i].first = x;
      edge[i].second = y;
    }
    for (int i = (1); i <= (m); i++) f[i] = true;
    for (int i = (1); i <= (m); i++) {
      if (f[i]) {
        x = edge[i].first;
        y = edge[i].second;
        for (auto &z : G[x])
          if (z != i) f[z] = false;
        for (auto &z : G[y])
          if (z != i) f[z] = false;
      }
    }
    p = 0;
    for (int i = (1); i <= (m); i++) {
      if (f[i]) p++;
    }
    if (p >= n) {
      cout << ("Matching") << endl;
      p = n;
      for (int i = (1); i <= (m); i++) {
        if (f[i]) cout << (i) << ' ', p--;
        if (p == 0) break;
      }
      cout << endl;
    } else {
      cout << ("IndSet") << endl;
      for (int i = (1); i <= (3 * n); i++) g[i] = true;
      for (int i = (1); i <= (m); i++) {
        if (f[i]) {
          x = edge[i].first;
          y = edge[i].second;
          g[x] = false;
          g[y] = false;
        }
      }
      p = n;
      for (int i = (1); i <= (3 * n); i++) {
        if (g[i]) cout << (i) << ' ', p--;
        if (p == 0) break;
      }
      cout << endl;
    }
  }
  return 0;
}
