#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int N,M;
vector<int> g[300030];

void solve(){
    cin>>N>>M;
    for(int i=1;i<=3*N;i++) g[i].clear();
    map<pair<int,int>,int> mp;
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
        if(a>b) swap(a,b);
        mp[mkp(a,b)]=i;
    }

    bool usedI[3*N+10]={};
    bool usedM[3*N+10]={};
    vector<pair<int,int>> match;
    vector<int> ind;
    
    vector<pair<int,int>> v;
    for(int i=1;i<=3*N;i++) v.push_back(mkp(g[i].size(),i));

    sort(v.begin(),v.end());

    for(int i=0;i<v.size();i++){
        int now=v[i].second;
        if(usedI[now]) continue;
        bool ok=true;
        for(auto nex:g[now]){
            if(usedI[nex]) ok=false;
        }
        if(ok){
            ind.push_back(now);
            usedI[now]=true;
        }
    }

    for(int i=0;i<v.size();i++){
        int now=v[i].second;
        if(usedM[now]) continue;
        int mi=M;
        int mit=-1;
        for(auto nex:g[now]){
            if(usedM[nex]) continue;
            if(mi>g[nex].size()) mit=nex;
            mi=min(mi,(int)g[nex].size());
        }

        if(mit==-1) continue;
        usedM[mit]=true;
        usedI[now]=true;
        if(now>mit) swap(now,mit);
        match.push_back(mkp(now,mit));
    }

    if(ind.size()>=N){
        cout<<"IndSet"<<endl;
        for(int i=0;i<N;i++) cout<<ind[i]<<" ";
        cout<<endl;
    }else if(match.size()>=N){
        cout<<"Matching"<<endl;
        int cnt=0;
        for(int i=0;i<N;i++){
            cout<<mp[match[i]]+1<<" ";
        }
        cout<<endl;
    }else cout<<"Impossible"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int T;
  cin>>T;
  for(int i=0;i<T;i++){
      solve();
  }

  return 0;
}
