#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  cin >> k;
  for (int l = 0; l < k; ++l) {
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> g(3 * n);
    int from, to;
    for (int i = 0; i < m; ++i) {
      cin >> from >> to;
      g[from - 1].emplace_back(to - 1, i + 1);
      g[to - 1].emplace_back(from - 1, i + 1);
    }
    vector<int> used(3 * n, 0);
    vector<int> ans;
    for (int i = 0; i < 3 * n; ++i) {
      if (!used[i])
        for (int j = 0; j < g[i].size(); ++j)
          if (!used[g[i][j].first]) {
            used[i] = true;
            used[g[i][j].first] = true;
            ans.emplace_back(g[i][j].second);
            break;
          }
    }
    if (ans.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; ++i) cout << ans[i] << ' ';
      cout << endl;
    } else {
      cout << "IndSet\n";
      int count = 0;
      for (int i = 0; i < 3 * n; ++i) {
        if (!used[i]) {
          cout << i + 1 << ' ';
          ++count;
        }
        if (count == n) {
          cout << endl;
          break;
        }
      }
    }
  }
}
