#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
void pre() {}
void solve() {}
struct UF {
  vector<int> e;
  UF(int n) : e(n, -1) {}
  bool same_set(int a, int b) { return find(a) == find(b); }
  int size(int x) { return -e[find(x)]; }
  int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
  void join(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return;
    if (e[a] > e[b]) swap(a, b);
    e[a] += e[b];
    e[b] = a;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> temp;
    int a, b, c, d, e, f;
    vector<vector<int>> ad(3 * n + 3);
    map<pair<int, int>, int> te;
    for (int i = 0; i < m; i++) {
      cin >> a >> b;
      if (a > b) swap(a, b);
      temp.push_back({a, b});
      te.insert({{a, b}, i});
    }
    sort(temp.begin(), temp.end());
    bool visited[3 * n + 3];
    memset(visited, 0, sizeof(visited));
    vector<pair<int, int>> temp1;
    if (temp.size() > 0) {
      temp1.push_back(temp[0]);
      visited[temp[0].first] = true;
      visited[temp[0].second] = true;
    }
    for (int i = 1; i < temp.size(); i++) {
      if (visited[temp[i].first] == true || visited[temp[i].second] == true) {
        continue;
      } else {
        temp1.push_back(temp[i]);
        visited[temp[i].first] = true;
        visited[temp[i].second] = true;
      }
    }
    if (temp1.size() >= n) {
      cout << "Matching" << endl;
      for (int i = 0; i < n; i++) {
        cout << te[temp1[i]] + 1 << " ";
      }
      cout << endl;
    } else {
      cout << "IndSet" << endl;
      a = 0;
      for (int i = 1; i <= 3 * n && a < n; i++) {
        if (visited[i] == false) {
          cout << i << " ";
          a++;
        }
      }
      cout << endl;
    }
  }
}
