#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
long long mod = 1e9 + 7;
long long fmod(long long b, long long exp) {
  long long res = 1;
  while (exp) {
    if (exp & 1ll) res = (res * b) % mod;
    b = (b * b) % mod;
    exp /= 2ll;
  }
  return res;
}
vector<int> adj[N], res;
int u[N], v[N];
int vis[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, i, j, k, x, q;
  int t = 1;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    int tot = 3 * n;
    res.clear();
    for (i = 1; i <= tot; i++) {
      adj[i].clear();
      vis[i] = 0;
    }
    for (i = 1; i <= m; i++) {
      cin >> u[i] >> v[i];
      adj[u[i]].push_back(v[i]);
      adj[v[i]].push_back(u[i]);
    }
    for (i = 1; i <= m; i++) {
      if (vis[u[i]] || vis[v[i]]) continue;
      res.push_back(i);
      vis[u[i]] = 1;
      vis[v[i]] = 1;
    }
    if (res.size() >= n) {
      cout << "Matching\n";
      for (i = 0; i < n; i++) cout << res[i] << " ";
    } else {
      cout << "IndSet\n";
      int cnt = 0;
      for (i = 1; i <= tot; i++) {
        if (cnt == n) break;
        if (!vis[i]) {
          cout << i << " ";
          cnt++;
        }
      }
    }
    cout << "\n";
  }
  return 0;
}
