#include <bits/stdc++.h>
using namespace std;
int get_num() {
  int num = 0;
  char c;
  bool flag = false;
  while ((c = getchar()) == ' ' || c == '\r' || c == '\n')
    ;
  if (c == '-')
    flag = true;
  else
    num = c - '0';
  while (isdigit(c = getchar())) num = (num << 3) + (num << 1) + c - '0';
  return (flag ? -1 : 1) * num;
}
int n, m;
const int maxn = 3e5 + 5;
int a, b;
int vis[maxn];
vector<int> e;
int main() {
  int t;
  t = get_num();
  while (t--) {
    n = get_num();
    m = get_num();
    for (int i = 1; i <= 3 * n; ++i) vis[i] = 0;
    e.clear();
    int cnt = 0;
    for (int i = 1; i <= m; ++i) {
      a = get_num();
      b = get_num();
      if (!vis[a] && !vis[b]) {
        vis[a] = vis[b] = 1;
        cnt++;
        e.push_back(i);
      }
    }
    if (cnt >= n) {
      printf("Matching\n");
      for (int i = 0; i < n; ++i) {
        printf("%d ", e[i]);
      }
      printf("\n");
      continue;
    }
    e.clear();
    cnt = 0;
    for (int i = 1; i <= 3 * n; ++i) {
      if (!vis[i]) {
        cnt++;
        e.push_back(i);
      }
    }
    if (cnt >= n) {
      printf("IndSet\n");
      for (int i = 0; i < n; ++i) {
        printf("%d ", e[i]);
      }
      printf("\n");
      continue;
    }
    printf("Impossible\n");
  }
  return 0;
}
