#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  for (int i = 0; i < T; i++) {
    int m, n;
    scanf("%d%d", &n, &m);
    vector<int> matchSet(3 * n + 1, 0);
    vector<int> matching;
    for (int j = 0; j < m; j++) {
      int s, e;
      scanf("%d%d", &s, &e);
      if (matching.size() == n) continue;
      if (!matchSet[s] && !matchSet[e]) {
        matchSet[s]++;
        matchSet[e]++;
        matching.push_back(j + 1);
      }
    }
    if (matching.size() == n) {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) {
        cout << matching[i];
        if (i != n - 1) cout << ' ';
      }
      cout << '\n';
    } else {
      cout << "IndSet\n";
      int ct = 0;
      int curr = 0;
      while (ct < n) {
        curr++;
        if (matchSet[curr])
          continue;
        else {
          cout << curr;
          if (ct != n - 1) cout << ' ';
          ct++;
        }
      }
      cout << '\n';
    }
  }
}
