#include <bits/stdc++.h>
using namespace std;
#define int long long
#include "string"
int32_t main(){
	int t;
	cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		vector<int>g[3*n+1];
		map<pair<int,int>,int>mp;
		for(int i=1,u,v;i<=m;i++){
			cin>>u>>v;
			if(u>v)
				swap(u,v);
			mp[{u,v}] = i;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		vector<int>edge;
		int visit[3*n+1]={0};
		for(int i=1;i<=3*n;i++){
			if(visit[i] != 0)
				continue;
			for(int v:g[i]){
				if(visit[v] != 0)
					continue;
				edge.push_back(mp[{min(i,v),max(i,v)}]);
				for(int u:g[i])
					visit[u] = 2;
				for(int u:g[v])
					visit[u] = 2;
				visit[i] = 1;
				visit[v] = 1;
				break;
			}
		}
		//print(visit,3*n);
		//print(edge);
		if(edge.size()>=n){
			cout<<"Matching"<<endl;
			for(int i=0;i<n;i++)
				cout<<edge[i]<<" ";
		}
		else{
			cout<<"IndSet"<<endl;
			int cnt = 0;
			for(int i=1;i<=3*n && cnt<n;i++){
				if(visit[i]!=1){
					cnt++;
					cout<<i<<" ";
				}
			}
		}
		cout<<endl;
	}	
}

 