#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 100;
int de[maxn];
int fa[maxn];
bool vis[maxn];
struct egde {
  int f, t, id;
  bool operator<(egde a) const { return de[f] + de[t] < de[a.f] + de[a.t]; }
} e[maxn];
int fin(int f) { return fa[f] == f ? fa[f] : fa[f] = fin(fa[f]); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= 3 * n; ++i) {
      vis[i] = 0;
      fa[i] = 0;
    }
    for (int i = 0; i < m; ++i) {
      cin >> e[i].f >> e[i].t;
      e[i].id = i;
      de[e[i].f]++;
      de[e[i].t]++;
    }
    vector<int> ans;
    for (int i = 0; i < m; ++i) {
      if (fa[e[i].f] || fa[e[i].t]) {
        continue;
      }
      ans.push_back(e[i].id + 1);
      fa[e[i].f] = 1;
      fa[e[i].t] = 1;
    }
    if (ans.size() >= n) {
      cout << "Matching" << endl;
      int cnt = 0;
      for (auto i : ans) {
        cout << i << " ";
        ++cnt;
        if (cnt == n) {
          break;
        }
      }
      cout << endl;
    } else {
      cout << "IndSet" << endl;
      int cnt = 0;
      for (int i = 1; i <= 3 * n; ++i) {
        if (fa[i]) continue;
        ++cnt;
        cout << i << " ";
        if (cnt == n) {
          cout << endl;
          break;
        }
      }
    }
  }
  return 0;
}
