#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const int maxn = 500050;
vector<pair<int, int> > v[maxn];
vector<int> bian, dian;
int vis[maxn];
int main() {
  int t, n, m;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) vis[i] = 0, v[i].clear();
    for (int i = 1; i <= m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      v[x].push_back(make_pair(y, i));
      v[y].push_back(make_pair(x, i));
    }
    bian.clear();
    dian.clear();
    int f = 0;
    for (int i = 1; i <= n; i++) {
      int flag = 0;
      for (int j = 0; j < v[i].size(); j++) {
        pair<int, int> u = v[i][j];
        if (vis[u.first]) continue;
        vis[i] = vis[u.first] = 1;
        flag = 1;
        bian.push_back(u.second);
        if (bian.size() == n) {
          printf("Matching\n");
          f = 1;
          for (int j = 0; j < bian.size(); j++)
            printf("%d%c", bian[j], j == bian.size() - 1 ? '\n' : ' ');
          break;
        }
      }
      if (!flag) {
        dian.push_back(i);
        if (dian.size() == n) {
          printf("IndSet\n");
          f = 1;
          for (int j = 0; j < dian.size(); j++)
            printf("%d%c", dian[j], j == dian.size() - 1 ? '\n' : ' ');
          break;
        }
      }
      if (f) break;
    }
    if (!f) printf("Impossible\n");
  }
  return 0;
}
