#include <bits/stdc++.h>
using namespace std;
int mk[300010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > edg;
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      edg.push_back(make_pair(a - 1, b - 1));
    }
    vector<int> ans;
    for (int i = 0; i < m; i++) {
      int a = edg[i].first;
      int b = edg[i].second;
      if (!mk[a] && !mk[b]) {
        ans.push_back(i + 1);
        mk[a] = 1;
        mk[b] = 1;
      }
    }
    if (ans.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) cout << ans[i] << ' ';
      cout << '\n';
    } else {
      cout << "IndSet\n";
      int ct = 0;
      for (int i = 0; i < 3 * n && ct < n; i++) {
        if (!mk[i]) {
          cout << i + 1 << " ";
          ct++;
        }
      }
      cout << '\n';
    }
  }
}
