#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
int t;
vector<vector<int>> g;
vector<vector<int>> gr;
vector<int> mt;
vector<bool> used, verts;
vector<int> part[2];
map<pair<int, int>, int> edges;
void dfs(int u, bool b) {
  used[u] = true;
  part[b].push_back(u);
  for (auto to : g[u]) {
    if (!b) {
      gr[u].push_back(to);
    }
    if (!used[to]) {
      dfs(to, !b);
    }
  }
}
bool try_khun(int v) {
  if (used[v]) return false;
  used[v] = true;
  for (auto to : g[v]) {
    if (mt[to] == -1) {
      mt[to] = v;
      return true;
    }
  }
  for (auto to : g[v]) {
    if (try_khun(mt[to])) {
      mt[to] = v;
      return true;
    }
  }
  return false;
}
int main() {
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    verts.assign(3 * n + 1, false);
    g.assign(3 * n + 1, vector<int>());
    gr.assign(3 * n + 1, vector<int>());
    mt.assign(3 * n + 1, -1);
    used.assign(3 * n + 1, false);
    edges.clear();
    int cnt = 0;
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
      if (u > v) swap(u, v);
      edges.insert(make_pair(make_pair(u, v), i + 1));
    }
    for (int v = 1; v <= 3 * n; ++v) {
      if (!used[v]) dfs(v, 0);
    }
    fill(used.begin(), used.end(), false);
    for (auto v : part[0]) {
      try_khun(v);
    }
    fill(used.begin(), used.end(), false);
    for (auto v : part[1]) {
      if (mt[v] != -1) {
        ++cnt;
        used[mt[v]] = true;
      }
    }
    if (cnt < n) {
      for (auto v : part[0]) {
        if (!used[v]) {
          ++cnt;
          used[v] = true;
          if (cnt == n) break;
        }
      }
      if (cnt < n) {
        cout << "Impossible\n";
      } else {
        cout << "IndSet\n";
        for (auto v : part[0]) {
          if (used[v]) {
            cout << v << ' ';
          }
        }
        cout << '\n';
      }
    } else {
      cout << "Matching\n";
      int c = 0;
      for (auto v : part[1]) {
        if (mt[v] != -1) {
          int tu = mt[v];
          int tv = v;
          if (tu > tv) swap(tu, tv);
          cout << edges[make_pair(tu, tv)] << ' ';
          ++c;
          if (c == n) break;
        }
      }
      cout << '\n';
    }
  }
  return 0;
}
