#include <bits/stdc++.h>
using namespace std;
const long long int N = 500005;
vector<pair<long long int, long long int> > gr[N];
long long int vis[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
    cin >> n >> m;
    for (i = 0; i < m; i++) {
      long long int x, y;
      cin >> x >> y;
      x--;
      y--;
      gr[x].push_back({y, i});
      gr[y].push_back({x, i});
    }
    vector<long long int> ansv;
    for (i = 1; i <= 3 * n; i++) {
      if (!vis[i]) {
        for (auto x : gr[i]) {
          if (!vis[x.first]) {
            vis[x.first] = 1;
            vis[i] = 1;
            ansv.push_back(x.second + 1);
            break;
          }
        }
      }
    }
    if (ansv.size() >= n) {
      cout << "Matching\n";
      for (i = 0; i < n; i++) {
        cout << ansv[i] << " ";
      }
    } else {
      cout << "IndSet\n";
      for (i = 0; i < 3 * n; i++) {
        if (!vis[i]) {
          cout << i + 1 << " ";
          cnt++;
        }
        if (cnt == n) break;
      }
    }
    for (i = 0; i < 3 * n; i++) {
      gr[i].clear();
      vis[i] = 0;
    }
    cout << '\n';
  }
}
