#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, pair<int, int>>> edges;
void solve() {
  vector<int> used(3 * n, 0);
  vector<int> ans;
  for (auto e : edges) {
    if (used[e.second.first] || used[e.second.second]) continue;
    used[e.second.first] = ++used[e.second.second];
    ans.push_back(e.first);
  }
  if (ans.size() >= n) {
    cout << "Matching\n";
    for (int i = 0; i < n; i++) cout << ans[i] << " ";
    cout << '\n';
    return;
  }
  used.clear();
  used.resize(3 * n, -1);
  vector<int> cont(2, 0);
  for (auto e : edges) {
    if (used[e.second.first] != -1 && used[e.second.second] != -1) continue;
    if (used[e.second.first] != -1) {
      used[e.second.second] = !used[e.second.first];
      cont[used[e.second.second]]++;
    } else if (used[e.second.second] != -1) {
      used[e.second.first] = !used[e.second.second];
      cont[used[e.second.first]]++;
    } else {
      used[e.second.first] = 0;
      used[e.second.second] = 1;
      cont[1]++;
      cont[0]++;
    }
  }
  if (cont[0] >= n) {
    cout << "IndSet\n";
    int a = 0;
    for (int i = 0; i < 3 * n; i++) {
      if (a == n) break;
      if (used[i] == 0) {
        cout << i + 1 << " ";
        a++;
      }
    }
  } else if (cont[1] >= n) {
    cout << "IndSet\n";
    int a = 0;
    for (int i = 0; i < 3 * n; i++) {
      if (a == n) break;
      if (used[i] == 1) {
        cout << i + 1 << " ";
        a++;
      }
    }
  } else {
    cout << "Impossible";
  }
  cout << '\n';
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int u, v;
    cin >> n >> m;
    edges.resize(m);
    for (int i = 0; i < m; i++) {
      cin >> u >> v;
      u--, v--;
      edges[i] = pair<int, pair<int, int>>(i + 1, pair<int, int>(u, v));
    }
    solve();
    edges.clear();
  }
  return 0;
}
