#include <bits/stdc++.h>
using namespace std;
const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int inf = 2147483647;
const long long linf = 1e15;
const double PI = acos(-1.0);
long long read() {
  long long t = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    t = t * 10 + ch - '0';
    ch = getchar();
  }
  return t * f;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
extern const int MAXN = 5e5 + 5;
extern const int N = 2000000;
int T, n, m, cnt = 0;
bool cover[MAXN];
int u[MAXN], v[MAXN];
vector<int> ans;
void init() { memset(cover, 0, sizeof(cover)), cnt = 0, ans.clear(); }
int work() {
  T = read();
  while (T--) {
    n = read(), m = read();
    for (int i = 1; i <= m; i++) u[i] = read(), v[i] = read();
    for (int i = 1; i <= m; i++)
      if (!cover[u[i]] && !cover[v[i]])
        cover[u[i]] = cover[v[i]] = 1, ans.push_back(i);
    if (ans.size() >= n) {
      puts("Matching");
      for (int i = 0; i < n; i++) printf("%d ", ans[i]);
      printf("\n");
    } else {
      puts("IndSet");
      for (int i = 1; i <= 3 * n && cnt < n; i++)
        if (!cover[i]) printf("%d ", i), cnt++;
      printf("\n");
    }
  }
}
int main() {
  work();
  return 0;
}
