#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const int M = 2e6 + 10;
const int inf = 0x3f3f3f3f;
int st[N];
int ans[N];
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int i;
    int cnt = 0;
    for (i = 1; i <= m; i++) {
      int a, b;
      cin >> a >> b;
      if (!st[a] && !st[b]) ans[++cnt] = i;
      st[a] = st[b] = 1;
    }
    if (cnt <= n) {
      cout << "IndSet" << endl;
      int id = 0;
      for (i = 1; i <= 3 * n; i++) {
        if (!st[i]) {
          cout << i << " ";
          id++;
        }
        if (id == n) {
          break;
        }
      }
    } else {
      cout << "Matching" << endl;
      for (i = 1; i <= n; i++) cout << ans[i] << " ";
      cout << endl;
    }
  }
}
