#include <bits/stdc++.h>
using namespace std;
inline void print(int n) {
  if (n == 0) {
    putchar('0');
    putchar('\n');
  } else if (n == -1) {
    putchar('-');
    putchar('1');
    putchar('\n');
  } else {
    char buf[11];
    buf[10] = '\n';
    int i = 9;
    while (n) {
      buf[i--] = n % 10 + '0';
      n /= 10;
    }
    while (buf[i] != '\n') putchar(buf[++i]);
  }
}
int read() {
  int cc = getc(stdin);
  for (; cc < '0' || cc > '9';) cc = getc(stdin);
  int ret = 0;
  for (; cc >= '0' && cc <= '9';) {
    ret = ret * 10 + cc - '0';
    cc = getc(stdin);
  }
  return ret;
}
bool visit[500005], visit1[500005], visit2[500005];
pair<int, int> pa[500005];
vector<int> vec[300005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n * 3; i++) vec[i + 1].clear();
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      vec[u].push_back(v);
      vec[v].push_back(u);
      pa[i] = make_pair(u, v);
    }
    priority_queue<pair<int, int>, vector<pair<int, int> >,
                   greater<pair<int, int> > >
        pq;
    for (int i = 0; i < 3 * n; i++) {
      int g = vec[i + 1].size();
      pq.push(make_pair(g, i + 1));
    }
    int f = 0;
    memset(visit, false, sizeof(bool) * (3 * n + 1));
    while (!pq.empty()) {
      int g = pq.top().first;
      int h = pq.top().second;
      pq.pop();
      bool is = false;
      for (int i = 0; i < vec[h].size(); i++) {
        if (visit[vec[h][i]]) {
          is = true;
          break;
        }
      }
      if (is == false) {
        f++;
        visit[h] = true;
      }
    }
    if (f > n) f = n;
    if (f == n) {
      cout << "IndSet\n";
      for (int i = 1; i <= 3 * n; i++) {
        if (visit[i]) cout << i << " ", f--;
        if (f == 0) break;
      }
      cout << endl;
      continue;
    }
    priority_queue<pair<pair<int, int>, pair<int, int> >,
                   vector<pair<pair<int, int>, pair<int, int> > >,
                   greater<pair<pair<int, int>, pair<int, int> > > >
        pq1;
    for (int i = 0; i < m; i++) {
      int u = pa[i].first;
      int v = pa[i].second;
      int g = vec[u].size();
      int h = vec[v].size();
      pq1.push(make_pair(make_pair(g + h, i), make_pair(u, v)));
    }
    memset(visit, false, sizeof(bool) * (3 * n + 1));
    memset(visit1, false, sizeof(bool) * (m));
    f = 0;
    int c[n * 3 + 1];
    for (int i = 0; i < 3 * n; i++) c[i + 1] = vec[i + 1].size();
    while (!pq1.empty()) {
      int x = pq1.top().first.second;
      int u = pq1.top().second.first;
      int v = pq1.top().second.second;
      pq1.pop();
      if (visit[u] || visit[v]) continue;
      visit[u] = true;
      visit[v] = true;
      visit1[x] = true;
      f++;
    }
    if (f > n) f = n;
    if (f == n) {
      cout << "Matching\n";
      for (int i = 0; i < m; i++) {
        if (visit1[i]) cout << i + 1 << " ", f--;
        if (f == 0) break;
      }
      cout << endl;
    } else
      cout << "Impossible\n";
  }
  return 0;
}
