#include <bits/stdc++.h>
template <typename T>
void scan(T &x) {
  x = 0;
  register bool _ = 0;
  register T c = getchar();
  _ = c == 45;
  c = _ ? getchar() : c;
  while (c < 48 || c > 57) c = getchar();
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15);
  x = _ ? -x : x;
}
template <typename T>
void printn(T n) {
  register bool _ = 0;
  _ = n < 0;
  n = _ ? -n : n;
  char snum[65];
  int i = 0;
  do {
    snum[i++] = n % 10 + 48;
    n /= 10;
  } while (n);
  --i;
  if (_) putchar(45);
  while (i >= 0) putchar(snum[i--]);
}
template <typename First, typename... Ints>
void scan(First &arg, Ints &...rest) {
  scan(arg);
  scan(rest...);
}
template <typename T>
void print(T n) {
  printn(n);
  putchar(10);
}
template <typename First, typename... Ints>
void print(First arg, Ints... rest) {
  printn(arg);
  putchar(32);
  print(rest...);
}
using namespace std;
const int MM = 5e5 + 1;
int T, n, m, c[MM];
bool no[MM];
vector<pair<int, int>> adj[MM];
pair<int, int> edge[MM];
vector<int> ans;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    q;
int main() {
  scan(T);
  while (T--) {
    scan(n, m);
    while (!q.empty()) q.pop();
    ans.clear();
    for (int i = 1; i <= 3 * n; i++) {
      c[i] = 0;
      no[i] = 0;
      adj[i].clear();
    }
    for (int i = 1, a, b; i <= m; i++) {
      scan(a, b);
      adj[a].push_back({b, i});
      adj[b].push_back({a, i});
      c[a]++, c[b]++;
      edge[i] = {a, b};
    }
    for (int i = 1; i <= 3 * n; i++) {
      q.push({adj[i].size(), i});
    }
    int cnt = 0;
    while (!q.empty()) {
      int rm = q.top().second;
      q.pop();
      if (no[rm]) continue;
      ans.push_back(rm);
      cnt++;
      if (cnt >= n) break;
      for (auto u : adj[rm]) no[u.first] = 1;
    }
    if (cnt >= n) {
      puts("IndSet");
      for (int i = 0; i < n; i++) printf("%d ", ans[i]);
      putchar(10);
      continue;
    }
    for (int i = 1; i <= 3 * n; i++) no[i] = 0;
    cnt = 0;
    ans.clear();
    while (!q.empty()) q.pop();
    for (int i = 1; i <= m; i++) {
      int v = c[edge[i].first] + c[edge[i].second];
      q.push({v, i});
    }
    while (!q.empty()) {
      int rm = q.top().second;
      q.pop();
      auto e = edge[rm];
      if (no[e.first] || no[e.second]) continue;
      cnt++;
      ans.push_back(rm);
      no[e.first] = no[e.second] = 1;
    }
    if (cnt >= n) {
      puts("Matching");
      for (int i = 0; i < n; i++) printf("%d ", ans[i]);
      putchar(10);
      continue;
    }
    puts("Impossible");
  }
  return 0;
}
