#include <bits/stdc++.h>
using namespace std;
inline void prnt(bool ok) { cout << (ok ? "YES" : "NO"); }
const int ppr = 257;
const long long INF = 2e18;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 1e6 + 123;
const long double pi = 3.141592653589793238462643;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int T, n, m;
bool u[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> T;
  while (T--) {
    cin >> n >> m;
    for (int i = 1; i <= 3 * n; i++) u[i] = 0;
    vector<int> cur;
    for (int i = 1; i <= m; i++) {
      int x, y;
      cin >> x >> y;
      if (u[x] || u[y]) continue;
      u[x] = u[y] = 1;
      cur.push_back(i);
    }
    if (cur.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) cout << cur[i] << ' ';
    } else {
      cout << "IndSet\n";
      int cnt = 0;
      for (int i = 1; i <= 3 * n; i++) {
        if (cnt == n) break;
        if (!u[i]) {
          cnt++;
          cout << i << ' ';
        }
      }
    }
    cout << '\n';
  }
  return 0;
}
