#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;
typedef vector <int> vi;
typedef pair <int, int> ii;

const int INF = 1 << 30;
const int maxn = 100010;

struct Edges {
    int v, id;
    Edges () {}
    Edges (int _v, int _id) : v(_v), id(_id) {}
};

int main() {
#ifdef BZ
    freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(6);

    int tc;
    cin >> tc;

    while (tc--) {
        int n, m;
        cin >> n >> m;

        vector <vector <Edges>> adj (n * 3 + 1);
        vector <ii> edges;

        for (int i = 0; i < m; i++) {
            int u, v;
            cin >> u >> v;
            edges.emplace_back(u, v);
            adj[u].emplace_back (v, i + 1);
            adj[v].emplace_back (u, i + 1);
        }

        set <int> match;
        set <int> is;
        vi ma;

        function <void(int, int)> find_match = [&] (int u, int v) {
            for (auto el: adj[u]) {
                if (el.v == v)
                    continue;
                match.insert (u);
                match.insert (el.v);
                ma.push_back (el.id);
                for (auto nel: adj[el.v]) {
                    if (nel.v != u) {
                        find_match(nel.v, el.v);
                    }
                }
            }
        };

        find_match (0, -1);

        if (ma.size() >= n) {
            cout << "Matching\n";
            for (auto el: ma)
                cout << el << " ";
            cout << "\n";
        } else {
            vi ans;
            for (int i = 1; i <= 3 * n; i++) {
                if (!match.count(i)) {
                    ans.push_back (i);
                }
            }
            ans.resize (n);
            cout << "IndSet\n";
            for (auto el: ans)
                cout << el << " ";
            cout << "\n";
        }
    }

}