#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define  pb(x) push_back(x)
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define mod 1000000007
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
int main()
{
	sync;
	ll t;
	cin>>t;
	while(t--)
	{
		ll n,m;
		cin>>n>>m;
		ll arr[3*n+1]={0};
		vector<ll>ans;
		for(ll i=1;i<=m;i++)
		{
			ll u,v;
			cin>>u>>v;
			if(!(arr[u]+arr[v]))
			{
				arr[u]=arr[v]=1;
				ans.push_back(i);
			}
		}
		if(ans.size()>=n)
		{
			cout<<"Matching\n";
			for(ll i=0;i<n;i++)
				cout<<ans[i]<<" ";
		}
		else
		{
			cout<<"IndSet\n";
			ll cnt=0;
			for(ll i=1;cnt<=n;i++)
			{
				if(!arr[i])
				{
					cout<<i<<" ";
					cnt++;
				}
			}
		}
		cout<<"\n";
	}
	}
