#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
bool visited[maxn];
struct edge {
  int u;
  int v;
} vertices[maxn];
int n, m;
vector<int> ans;
bool matching() {
  for (int i = 0; i <= 3 * n; i++) visited[i] = false;
  for (int i = 0; i < m; i++) {
    if (!visited[vertices[i].u] && !visited[vertices[i].v]) {
      visited[vertices[i].u] = true;
      visited[vertices[i].v] = true;
      ans.push_back(i + 1);
      if (ans.size() == n) return true;
    }
  }
  return false;
}
bool indSet() {
  ans.clear();
  for (int i = 0; i < 3 * n; i++) {
    if (!visited[i + 1]) {
      ans.push_back(i + 1);
      visited[i + 1] = true;
      if (ans.size() == n) return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    ans.clear();
    cin >> n >> m;
    for (int i = 0; i < m; i++) cin >> vertices[i].u >> vertices[i].v;
    if (matching()) {
      cout << "Matching" << endl;
      for (int i = 0; i < n; i++) {
        cout << ans[i] << ' ';
      }
      cout << endl;
    } else if (indSet()) {
      cout << "IndSet" << endl;
      for (int i = 0; i < n; i++) {
        cout << ans[i] << ' ';
      }
      cout << endl;
    } else {
      cout << "Impossible" << endl;
    }
  }
  return 0;
}
