#include <bits/stdc++.h>    
#define pb push_back
 
#define FOR(x,to) for(int x=0;x<(to);x++)
#define F0R(x,in,to) for(int x=(in);x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
 
typedef long long ll;
using namespace std;
ll MOD = 998244353;
 
typedef pair<int,int> ii;
typedef struct {int a,b,c;}iii;
typedef vector<int> vi;	
 
void mosA(vector<int> a){
	for(int i=0; i<a.size(); i++) printf("%d ",a[i]);
	printf("\n");
}
 
 
void mosP(vector<ii> a){
	for(int i=0; i<a.size(); i++) printf("%d %d\n",a[i].first,a[i].second);
	printf("\n");
}
 
ll min_especial(ll a, ll b){
  if(a!=-1 && b!=-1) return min(a,b);
  else return max(a,b);
}
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
//<key,mapped type,comparator,...>
typedef tree<int,null_type,less<int>,rb_tree_tag,
	tree_order_statistics_node_update> ordered_set;
 
ll ans = 0, sum = 0, pos,d;
int a,n,w,t,k,m,z,q,l,r,x,b,c,y,s,p;
 
char S[300005];
 
vi G[200005];
bool vis[200005];
 
ll A[400005];
ll C[400005];
 
vi v;
 
bool sePuede(int i, int j){
	if(ceil(log2(j-i+1))*n<=k) return 1;
	return 0;
}
 
int main()
{
	scanf("%d",&t);

	while(t--){
		scanf("%d%d",&n,&m);
		vector<ii> e;
		set<int> v;
		vi eM;
		FOR(i,m){ 
			scanf("%d%d",&a,&b);
			e.pb({a,b});
			v.insert(a);
			v.insert(b);
		}

		FOR(i,m){
			auto it1 = v.find(e[i].first);
			auto it2 = v.find(e[i].second);
			if(it1 != v.end() && it2 != v.end()){
				v.erase(it1);
				v.erase(it2);
				eM.pb(i+1);
			}
		}

		if(eM.size()>=n){
			printf("Matching\n");
			mosA(eM);
		} else {	
			printf("IndSet\n");
			for(auto x:v) printf("%d ",x);
			printf("\n");
		}

	}
	
 
}
 
 
// REVISATE ESTO:
// - memset(A,-1,SIZEOF()*n)
// - (x-y+MOD)%MOD
// - int o ll?