#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> inv_help(long long a, long long b) {
  pair<long long, long long> res;
  res.first = 1;
  res.second = 0;
  if (b == 0)
    return res;
  else {
    pair<long long, long long> res1 = inv_help(b, a % b);
    res.first = res1.second;
    res.second = res1.first - (a / b) * res1.second;
    return res;
  }
}
long long inv(long long a, long long b) {
  pair<long long, long long> res = inv_help(a, b);
  long long x = res.first;
  if (x > 0) x = x % b;
  if (x < 0) x = (b - (-x) % b) % b;
  return x;
}
vector<int> l;
int N;
int binsearch(int p, int l_bnd) {
  int i = l_bnd, j = N - 1, k;
  if (l_bnd > N - 1) return -1;
  if (l[N - 1] < p)
    return -1;
  else if (l[i] > p)
    return i;
  else {
    while (i != j) {
      k = (i + j) / 2;
      if (i == j) {
        return i;
      } else if (i == j - 1) {
        if (l[i] == p)
          return i;
        else
          return i + 1;
      } else if (l[k] < p) {
        i = k + 1;
      } else if (l[k] >= p) {
        j = k;
      }
    }
    return i;
  }
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    int x, y;
    vector<vector<int> > v(3 * n + 1, vector<int>(0, 0)),
        e(3 * n + 1, vector<int>(0, 0));
    for (int i = 0; i < m; i++) {
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
      e[x].push_back(i + 1);
      e[y].push_back(i + 1);
    }
    vector<int> matching(m, -1), vertices(3 * n + 1, 1), z(3 * n + 1, -1);
    int unused = 3 * n;
    int i = 1, sz;
    while (unused > n && i <= 3 * n) {
      while (vertices[i] == -1) {
        i++;
        if (i > 3 * n) break;
      }
      if (i > 3 * n) break;
      sz = v[i].size();
      int found = 0;
      for (int j = 0; j < sz; j++) {
        if (vertices[v[i][j]] == 1) {
          matching[e[i][j]] = 1;
          vertices[i] = -1;
          vertices[v[i][j]] = -1;
          z[i] = 1;
          z[v[i][j]] = 1;
          unused--;
          unused--;
          found = 1;
          for (int k = 0; k < sz; k++) {
            vertices[v[i][k]] = -1;
          }
        }
      }
      if (found == 0) {
        i++;
      }
    }
    if (unused > n) {
      cout << "IndSet\n";
      int i = 0, j = 1;
      while (i < n) {
        if (z[j] == -1) {
          cout << j << "\n";
          i++;
        }
        j++;
      }
    } else {
      int i = 0, j = 0;
      cout << "Matching\n";
      while (i < n) {
        if (matching[j] == 1) {
          i++;
          cout << j << "\n";
        }
        j++;
      }
    }
  }
}
