#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI                acos(-1)
#define pb                emplace_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);

ii edges[500010];
int nodos[300010], Es[500010];
vi G[300010];

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int t;
    cin >> t;
    double timePerTest = 0.90 / ( (double)t );
    while (t--)
    {
    	int n, m;
    	cin >> n >> m;
    	for (int i = 0; i < 3*n; i++)
    	{
    		nodos[i] = i;
    		G[i].clear();
    	}
    	for (int i = 0; i < m; i++)
    	{
    		int a, b;
    		cin >> a >> b;
    		a--; b--;
    		edges[i] = mp(a, b);
    		Es[i] = i;
    		G[a].pb(b);
    		G[b].pb(a);
    	}
    	bool match = false, ind = false;
    	double t = clock();
    	vi matchSet, indSet;
    	while( !match && !ind && (clock()-t) / CLOCKS_PER_SEC < timePerTest)
    	{
    		random_shuffle( nodos, nodos+3*n );
    		random_shuffle( Es, Es+m );
    		set<int> usedNodes;
    		matchSet.clear();
    		indSet.clear();
    		for (int i = 0; i < m; i++)
    		{
    			int a = edges[ Es[i] ].F;
    			int b = edges[ Es[i] ].S;
    			if ( usedNodes.count(a) || usedNodes.count(b) ) continue;
    			matchSet.pb( Es[i] +1);
    			if (matchSet.size() == n)
    			{
    				match = true;
    				break;
    			}
    			usedNodes.insert(a);
    			usedNodes.insert(b);
    		}
    		if (match) break;

    		usedNodes.clear();
    		for (int i = 0; i < 3*n; i++)
    		{
    			int v = nodos[i];
    			if ( usedNodes.count(v) ) continue;
    			indSet.pb(v+1);
    			if (indSet.size() == n)
    			{
    				ind = true;
    				break;
    			}
    			for (int u : G[v])
    			{
    				usedNodes.insert(u);
    			}
    		}
    		if (ind) break;
    	}
    	if (match)
    	{
    		cout << "Matching" << '\n';
    		for (int x : matchSet)
    		{
    			cout << x << " ";
    		}
    		cout << '\n';
    	}
    	else if (ind)
    	{
    		cout << "IndSet" << '\n';
    		for (int x : indSet)
    		{
    			cout << x << " ";
    		}
    		cout << '\n';
    	}
    	else cout << "Impossible" << '\n';
    }
    return 0;
}
// PLUS ULTRA!