#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  for (int zes = 0; zes < T; zes++) {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<pair<int, int>> edges(m);
    vector<int> visited(3 * n, 0);
    for (int i = 0; i < m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      x--;
      y--;
      edges[i].first = x;
      edges[i].second = y;
    }
    int ile_krawedzi = 0;
    vector<int> matching;
    for (int i = 0; i < m; i++) {
      if (ile_krawedzi < n) {
        if (visited[edges[i].first] || visited[edges[i].second])
          continue;
        else {
          visited[edges[i].first] = true;
          visited[edges[i].second] = true;
          ile_krawedzi++;
          matching.push_back(i);
        }
      }
    }
    if (ile_krawedzi == n) {
      printf("Matching\n");
      while (!matching.empty()) {
        printf("%d ", matching.back() + 1);
        matching.pop_back();
      }
      printf("\n");
    } else {
      int ile_wierzch = 0;
      printf("IndSet\n");
      for (int i = 0; i < 3 * n; i++) {
        if (ile_wierzch == n) {
          break;
        }
        if (!visited[i]) {
          printf("%d ", i + 1);
          ile_wierzch++;
        }
      }
      printf("\n");
    }
  }
}
