#include <bits/stdc++.h>
using namespace std;
void f() {
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    int n, m;
    cin >> n >> m;
    vector<bool> covered(3 * n + 1);
    int uncovered = 3 * n;
    vector<int> matching;
    for (int j = 0; j < m; j++) {
      int u, v;
      cin >> u >> v;
      if (covered[u] == 0 && covered[v] == 0) {
        matching.push_back(j + 1);
        covered[u] = 1;
        covered[v] = 1;
        uncovered -= 2;
      }
    }
    if (matching.size() >= n) {
      cout << "Matching" << endl;
      for (int j = 0; j < n; j++) {
        cout << matching[j];
        if (j != n - 1) cout << " ";
      }
    } else if (uncovered >= n) {
      int printed = 0;
      cout << "IndSet" << endl;
      for (int j = 1; j <= 3 * n; j++) {
        if (covered[j] == 0) {
          cout << j;
          if (printed != n - 1) cout << " ";
          printed++;
        }
        if (printed == n) break;
      }
    } else
      cout << "Impossible";
    cout << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  f();
  return 0;
}
