#include <bits/stdc++.h>
using namespace std;
long long modexpo(long long x, long long p) {
  int res = 1;
  x = x % 1000000007;
  while (p) {
    if (p % 2) res = res * x;
    p >>= 1;
    x = x * x % 1000000007;
    res %= 1000000007;
  }
  return res;
}
struct compare {
  bool operator()(const pair<int, int> a, const pair<int, int> b) const {
    return a.first < b.first;
  }
};
const int nax = 1e5 + 5;
int n, m;
int vis[3 * nax];
vector<pair<int, int>> g[3 * nax];
vector<int> ans;
void reset() {
  for (int i = 0; i <= 3 * n; i++) {
    vis[i] = 0;
    g[i].clear();
  }
  ans.clear();
}
void solve() {
  cin >> n >> m;
  reset();
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (vis[a] == 0 && vis[b] == 0 && ans.size() < n) {
      vis[a] = 1;
      vis[b] = 1;
      ans.push_back(i + 1);
    }
    g[a].push_back({b, i + 1});
    g[b].push_back({a, i + 1});
  }
  if (ans.size() == n) {
    cout << "Matching" << endl;
    for (int i : ans) {
      cout << i << " ";
    }
    cout << endl;
    return;
  }
  ans.clear();
  for (int i = 1; i <= 3 * n; i++) {
    if (vis[i]) {
      continue;
    }
    vis[i] = 1;
    int c = 0;
    for (auto j : g[i]) {
      if (!vis[j.first]) {
        c = 1;
        break;
      }
    }
    if (c == 0 && ans.size() < n) {
      ans.push_back(i);
    }
  }
  if (ans.size() == n) {
    cout << "IndSet" << endl;
    for (int i : ans) {
      cout << i << " ";
    }
    cout << endl;
    return;
  }
  cout << "Impossible" << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
