#include <bits/stdc++.h>
long double PI = 3.141592653589793238462643383279502884197;
using namespace std;
int arr[300001];
bool use[300001];
vector<int> vec[300001];
vector<pair<int, int> > vv;
int main() {
  int t, n, m, a, b;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &n, &m);
    fill(arr, arr + n + 1, 0);
    for (int i = 1; i <= n; i++) vec[i].clear(), use[i] = false;
    vv.clear();
    for (int i = 0; i < m; i++) {
      scanf("%d %d", &a, &b);
      vv.push_back({a, b});
      arr[a]++, arr[b]++;
      vec[a].push_back(b);
      vec[b].push_back(a);
    }
    for (int i = 1; i <= n; i++) {
      sort(vec[i].begin(), vec[i].end());
    }
    if (1LL * 3 * n * (3 * n - 1) / 2 - m >= 1LL * n * (n - 1) / 2) {
      printf("IndSet\n");
      int cnt = 0;
      for (int i = 1; i <= 3 * n; i++) {
        if (!use[i] && arr[i] < 3 * n - 1) {
          for (int j = 1; j <= 3 * n; j++) {
            if (j > vec[i].size() || vec[i][j - 1] != j) {
              use[i] = use[j] = true;
              printf("%d ", i);
              cnt++;
              break;
            }
          }
        }
        if (cnt == n) break;
      }
      printf("\n");
    } else {
      printf("Matching\n");
      int cnt = 0;
      for (int i = 0; i < m; i++) {
        if (!use[vv[i].first] && !use[vv[i].second]) {
          use[vv[i].first] = use[vv[i].second] = true;
          printf("%d ", i + 1);
          cnt++;
        }
        if (cnt == n) break;
      }
      printf("\n");
    }
  }
  return 0;
}
