#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
int TC, n, m, a, b, u, c;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> TC;
    while(TC--)
    {
        cin >> n >> m, n *= 3;
        vector< vector<int> >adj(n + 5);
        bool vis[n + 5] = {};
        vector<int>nodes, edges;
        map< pair<int, int>, int >mp;
        map <int, int>fq;
        for(int i = 1;i <= m;++i)
            cin >> a >> b, adj[a].push_back(b), adj[b].push_back(a), mp[{min(a, b), max(a, b)}] = i;
        priority_queue< pair<int, int> >mxPq;
        for(int i = 1;i <= n;++i)
            mxPq.push({adj[i].size(), i}), fq[i] = adj[i].size();
        while(mxPq.size())
        {
            u = mxPq.top().S, c = mxPq.top().F, mxPq.pop();
            if(vis[u])      continue;
            if(fq[u] < c)   continue;
            vis[u] = 1;
            if(!c)
            {
                nodes.push_back(u);
                continue;
            }
            for(auto it : adj[u])
                if(!vis[it])
                    --fq[it], mxPq.push({fq[it], it});
        }
        priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > >mnPq;
        memset(vis, 0, sizeof vis);
        for(int i = 1;i <= n;++i)
            mnPq.push({adj[i].size(), i});
        while(mnPq.size())
        {
            u = mnPq.top().S, mnPq.pop();
            if(vis[u])  continue;
            int mn = INT_MAX, ans = -1;
            for(auto it : adj[u])
                if(adj[it].size() < mn && !vis[it])
                    mn = adj[it].size(), ans = it;
            if(ans != -1)
                vis[u] = vis[ans] = 1, edges.push_back(mp[{min(u, ans), max(u, ans)}]);
        }
        n /= 3;
        if(nodes.size() >= n)
        {
            cout << "IndSet\n";
            for(int i = 0;i < n;++i)
                cout << nodes[i] << ' ';
        }
        else if(edges.size() >= n)
        {
            cout << "Matching\n";
            for(int i = 0;i < n;++i)
                cout << edges[i] << ' ';
        }
        else
            cout << "Impossible";
        cout << '\n';
    }
    return 0;
}
