#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
const int logn = (log(maxn) / log(2)) + 5;
const int inf = 0x3f3f3f3f;
const long double eps = 1e-9;
int a[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<int> ans;
    for (int i = (0); i < (m); i++) {
      int x, y;
      cin >> x >> y;
      if (!a[x] && !a[y]) {
        a[x] = a[y] = 1;
        ans.push_back(i + 1);
      }
    }
    int t = 3 * n;
    if ((int)ans.size() >= n) {
      cout << "Matching"
           << "\n";
      for (int i = 0; i < n; i++) cout << ans[i] << ' ';
    } else {
      cout << "IndSet"
           << "\n";
      int k = 0;
      for (int i = 1; i <= t && k < n; i++) {
        if (!a[i]) cout << i << ' ', k++;
      }
    }
    for (int i = (1); i < (t + 1); i++) a[i] = 0;
    cout << "\n";
  }
  return 0;
}
