#include <bits/stdc++.h>
using namespace std;
int const N = 1e6 + 4, inf = 1e9;
long long const md = 998244353;
long long dp[N], a[N], pref[N][5], n, k, m, x1, y, x, bbp, kk, sz, ans;
long long q, qq;
char ch;
vector<long long> v;
bool us[N];
pair<long long, long long> p[N];
string second, t;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> qq;
  for (int ii = 0; ii < qq; ii++) {
    cin >> n >> m;
    vector<long long> vv;
    for (int i = 0; i <= 3 * n; i++) {
      us[i] = 0;
    }
    for (int i = 0; i < m; i++) {
      cin >> x >> y;
      if (!us[x] && !us[y]) {
        vv.push_back(i + 1);
        us[x] = 1;
        us[y] = 1;
      }
    }
    if (vv.size() >= n) {
      cout << "Matching" << endl;
      for (int i = 0; i < n; i++) {
        cout << vv[i] << " ";
      }
      cout << endl;
    } else {
      cout << "IndSet" << endl;
      k = 0;
      for (int i = 1; i <= n + n + n; i++) {
        if (k == n) break;
        if (!us[i]) k++, cout << i << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
