#include <bits/stdc++.h>
using namespace std;
void ECHO(string _s) {
  cout << endl;
  (void)_s;
}
template <typename T, typename... Args>
void ECHO(string _s, T x, Args... args) {
  unsigned _i;
  string _s2 = "";
  for (_i = 0; _i < _s.length(); ++_i) {
    if (_s[_i] == ',') break;
    if (_s[_i] != ' ') _s2 += _s[_i];
  }
  if (_i == _s.length()) {
    --_i;
  }
  cout << "  (" << _s2 << "):" << x;
  ECHO(_s.substr(_i + 1, _s.length() - _i - 1), args...);
}
template <typename T0, typename T1>
inline ostream& operator<<(ostream& os, pair<T0, T1>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
  for (unsigned i = 0; i < v.size(); ++i) {
    cout << v[i] << "_";
  }
  cout << endl;
  return os;
}
template <typename T>
inline T _min(T x1, T x2, T x3) {
  return min(x1, min(x2, x3));
}
template <typename T>
inline T _min(T x1, T x2, T x3, T x4) {
  return min(min(x1, x2), min(x2, x3));
}
inline int _gcd(int a, int b) {
  while (b) b %= a ^= b ^= a ^= b;
  return a;
}
bool taken[300006];
vector<pair<int, int> > edges;
int main() {
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  while (q--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < 3 * n; i++) taken[i] = false;
    pair<int, int> a;
    edges.clear();
    edges.reserve(m);
    for (int i = 0; i < m; i++) {
      cin >> a.first >> a.second;
      a.first--;
      a.second--;
      edges.push_back(a);
    }
    vector<int> tak;
    for (int i = 0; i < m; i++) {
      a = edges[i];
      if (!taken[a.first] && !taken[a.second]) {
        taken[a.first] = taken[a.second] = true;
        tak.push_back(i);
      }
    }
    if (tak.size() < n) {
      cout << "IndSet\n";
      bool b = 0;
      int count = 0;
      for (int i = 0; i < 3 * n; i++) {
        if (!taken[i]) {
          if (b) cout << " ";
          b = true;
          cout << i + 1;
          count++;
          if (count == n) break;
        }
      }
    } else {
      cout << "Matching\n";
      bool b = false;
      int count = 0;
      for (auto a : tak) {
        if (b) cout << " ";
        b = true;
        cout << a + 1;
        count++;
        if (count == n) break;
      }
    }
    cout << "\n";
  }
  return 0;
}
