#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    n *= 3;
    vector<int> eds;
    int nd[n + 1];
    for (int i = 1; i <= n; i++) nd[i] = 1;
    int ed[n + 1];
    memset(ed, 0, sizeof(ed));
    for (int i = 1; i <= m; i++) {
      int a, b;
      cin >> a >> b;
      if (nd[a] && nd[b]) {
        if (ed[a]) {
          nd[a] = 0;
        } else if (ed[b]) {
          nd[b] = 0;
        } else {
          ed[a] = ed[b] = 1;
          eds.push_back(i);
          nd[b] = 0;
        }
      } else {
        if ((!ed[a]) && (!ed[b])) {
          ed[a] = ed[b] = 1;
          eds.push_back(i);
        }
      }
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) cnt += nd[i];
    n /= 3;
    if (eds.size() >= n) {
      cout << "Matching\n";
      for (int i = 0; i < n; i++) cout << eds[i] << " ";
      cout << endl;
    } else if (cnt >= n) {
      cout << "IndSet\n";
      int cnt = 0;
      for (int i = 1; i <= 3 * n; i++) {
        if (nd[i]) cout << i << " ";
        cnt += nd[i];
        if (cnt == n) break;
      }
      cout << endl;
    } else
      cout << "Impossible\n";
  }
  return 0;
}
