#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> g;
vector<int> ans;
int n, m;
vector<int> used;
bool try_par() {
  used.clear();
  used.resize(3 * n + 1);
  vector<pair<int, pair<int, int>>> vec;
  for (int i = 1; i <= 3 * n; ++i) {
    for (auto j : g[i]) {
      vec.push_back({j.second, {i, j.first}});
    }
  }
  random_shuffle(vec.begin(), vec.end());
  ans.clear();
  for (auto i : vec) {
    if (used[i.second.first] == 0 && used[i.second.second] == 0) {
      used[i.second.first] = 1;
      used[i.second.second] = 1;
      ans.push_back(i.first);
    }
  }
  if (ans.size() >= n) return true;
  return false;
}
bool try_ind() {
  used.clear();
  ans.clear();
  used.resize(3 * n + 1);
  vector<int> vec;
  for (int i = 1; i <= 3 * n; ++i) vec.push_back(i);
  random_shuffle(vec.begin(), vec.end());
  for (auto i : vec) {
    if (used[i] == 0) {
      used[i] = 1;
      ans.push_back(i);
      for (auto j : g[i]) used[j.first] = 1;
    }
  }
  if (ans.size() >= n) return true;
  return false;
}
int main() {
  srand(clock());
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int test;
  cin >> test;
  for (int t = 1; t <= test; ++t) {
    cin >> n >> m;
    g.clear();
    g.resize(3 * n + 1);
    for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      g[x].push_back({y, i + 1});
      g[y].push_back({x, i + 1});
    }
    int p = 0;
    while (p == 0) {
      ans.clear();
      if (try_par()) {
        cout << "Matching" << endl;
        for (int i = 0; i < n; ++i) {
          cout << ans[i] << ' ';
        }
        cout << endl;
        p = 1;
        continue;
      }
      ans.clear();
      if (try_ind()) {
        cout << "IndSet" << endl;
        for (int i = 0; i < n; ++i) {
          cout << ans[i] << ' ';
        }
        cout << endl;
        p = 1;
        continue;
      }
    }
  }
  return 0;
}
