#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
vector<pair<int, int>> v1[MAXN];
bool visited[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    n *= 3;
    for (int i = 1; i <= n; i++) {
      v1[i].clear();
      visited[i] = false;
    }
    for (int i = 1; i <= m; i++) {
      int x, y;
      cin >> x >> y;
      v1[x].push_back(make_pair(y, i));
      v1[y].push_back(make_pair(x, i));
    }
    vector<int> notused;
    vector<int> maxmatching;
    for (int i = 1; i <= n; i++) {
      if (visited[i]) {
        continue;
      }
      pair<int, int> mp = make_pair(-1, -1);
      for (auto x : v1[i]) {
        if (!visited[x.first]) {
          mp = x;
        }
      }
      if (mp.first > 0) {
        visited[i] = true;
        visited[mp.first] = true;
        maxmatching.push_back(mp.second);
      } else {
        visited[i] = true;
        notused.push_back(i);
      }
    }
    if (maxmatching.size() >= n / 3) {
      cout << "Matching" << endl;
      for (int i = 0; i < n / 3; i++) {
        cout << maxmatching[i] << " ";
      }
      cout << endl;
    } else if (notused.size() >= n / 3) {
      cout << "IndSet" << endl;
      for (int i = 0; i < n / 3; i++) {
        cout << notused[i] << " ";
      }
      cout << endl;
    } else {
      cout << "Impossible" << endl;
    }
  }
}
