
// Problem : E. Matching vs Independent Set
// Contest : Codeforces - Codeforces Round #576 (Div. 2)
// URL : https://codeforces.com/contest/1199/problem/E
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

 /* ..Mission 1900 soon.. */

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse2") 

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>


using namespace std;
using namespace __gnu_pbds;



#define MOD1          998244353
#define MOD           1000000007
#define M             1000000009
#define pye           acos(-1)
#define int           long long
#define ld            long double
#define D             double
#define S             second
#define F             first
#define pb            push_back
#define ff            fflush(stdout)
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define SORT(v)       sort(ALL(v))  
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define gcd(a,b)      __gcd(a,b)
#define lcm(a,b)      (a*(b/gcd(a,b)))
#define fast          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define accuracy      cout << fixed << setprecision(18);
#define pow(i,n)      (ll)pow((int)i,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define deb(x)        cout<<#x<<" "<<x<<endl;
#define debg         cout<<"I am here!"<<endl;
#define maxe(v)       *max_element(ALL(v))
#define mine(v)       *min_element(ALL(v))
#define endl          '\n'
#define tp            template
#define ty            typename
#define mem1(a)       memset(a,-1,sizeof(a))
#define mem0(a)       memset(a,0,sizeof(a))
#define bpc           __builtin_popcount
#define rep(b)    for(int i=0;i<b;i++)


const long double pi  = 3.141592653589793238463;

#ifdef magneto07
#define TRACE
#endif
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
    //use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...) 0;
#endif


typedef vector<int>                         vi;
typedef pair<int,int>                       pii;
typedef vector<pii>                         vpi;
typedef pair<int,pii>                       pipii;
typedef vector<vector<int>>                 vvi;
typedef map<int,int>                        mp;
typedef priority_queue<pii, vector<pii>, greater<pii> > pq;
typedef tree < int ,  null_type ,  less_equal<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;

inline  bool checkBit(int n, int i) { return n&((int)1<<i); }
inline  int setBit(int n, int i) { return n|((int)1<<i); }
inline  int resetBit(int n,int  i) { return n&(~((int)1<<i)); }
inline  void normal(int &a) { a = (a+MOD)%MOD; }
inline  int modMul(int a, int b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  int modAdd(int a,int b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  int modSub(int a, int b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  int modPow(int b, int p) { int r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  int modInv(int a) { return modPow(a, MOD-2); }
inline  int modDiv(int a,int b) { return modMul(a, modInv(b)); }


inline  int fact(int r){ int ans=1;while(r)ans=modMul(ans,r),r--;return ans; }
inline  int invfact(int r){int ans=1;while(r)ans=modMul(ans,modInv(r)),r--; return ans;}
inline  D dgcd(D a,D b){ if(a<b)return dgcd(b,a); if(b<.0001)return a; return dgcd(b,fmod(a,b));}


inline int toint(const std::string &s) {std::stringstream ss; ss << s; int x; ss >> x; return x;}
inline std::string tostring(int number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(int x) {return std::bitset<63>(x).to_string();}

//primes for hashing 937,991,1013,1409,1741

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

 
tp<ty T1, ty T2> istream& operator>>(istream& in, pair<T1, T2> &q){
    in >> q.F >> q.S; return in;
}
tp<ty T1, ty T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}
tp< ty T1, ty T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}
tp< ty T1, ty T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}

template <typename Arg1, typename... Args>

void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template <typename T> T allmin(T t) {return t;}

template<typename T, typename... Args> T allmin(T t, Args... args) {return min(t, allmin(args...));}
 
template <typename T> T allmax(T t) {return t;}

template<typename T, typename... Args> T allmax(T t, Args... args) {return max(t, allmax(args...));}

 
/*----------------------Graph Moves----------------------*/
// const int fx[]={+1, -1, +0, +0};
// const int fy[]={+0, +0, +1, -1};
// const int fx[]={+0, +0, +1, -1, -1, +1, -1, +1};  // Kings Move
// const int fy[]={-1, +1, +0, +0, +1, +1, -1, -1};  // Kings Move
// const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
// const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1};  // Knights Move
/*-------------------------------------------------------*/

const int N=202;
const int INF=2e18;
   
int power( int base, int exp) {
    int res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%MOD;
       base=(base*base)%MOD;
       exp/=2;
    }
    return res%MOD;
} 


bool isPrime(int n) {
 
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}
vector<pair<int,int>> ans;
vector<int> ans1;
void dfs(int x,vector<vector<int>>& v,vector<int>& vis,int ok){
	vis[x]=1;
	for(auto it:v[x]){
		if(!vis[it]){
			if(ok)
			ans.pb({it,x});
			else
			ans1.pb(it+1);
			dfs(it,v,vis,ok^1);
			if(ok)
			ok^=1;	
		}
	}
}
void Timelimitexceeded()
{   
    int n,m;
    cin>>n>>m;
    int k=3*n;
    vector<vector<int>> v(k);
    ans.clear();
    ans1.clear();
    vector<int> vis(k,0);
    map<pair<int,int>,int> c;
    for(int i=0;i<m;i++){
    	int x,y;
    	cin>>x>>y;
    	x--,y--;
    	v[x].pb(y);
    	v[y].pb(x);
    	c[{x,y}]=i+1;
    	c[{y,x}]=i+1;
    }
    	for(int i=0;i<k;i++)
    	if(!vis[i])
    	dfs(i,v,vis,1);
	
	if(ans.size()>=n){
		cout<<"Matching"<<endl;
		int cnt=0;
		for(auto it:ans){
			if(cnt<n)
			cout<<c[{it.F,it.S}]<<" ";
			else
			break;
			cnt++;
		}
		cout<<endl;
		return;
	}
	if(ans1.size()>=n){
		cout<<"IndSet"<<endl;
		int cnt=0;
		for(auto it:ans1){
			if(cnt<n)
			cout<<it<<" ";
			else
			break;
		cnt++;
		}	
		cout<<endl;
		return;
	}
	
	cout<<"Impossible"<<endl;
return;
}

signed main()
{  
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);    
    int t = 1;
    clock_t start, end; 
    start = clock(); 
    cout << fixed << setprecision(20);
    cin>>t;
    while(t--){
        Timelimitexceeded();
    }
    end = clock();
    double time_taken = double(end - start) / double(CLOCKS_PER_SEC); 
    //cerr<<time_taken;
}