#include <bits/stdc++.h>

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int maxn = 3e5 + 7;
long long mod = 1e9 + 7;


mt19937 ran( time( 0 ));


inline int random( ) {
    return abs(( int ) ran( ));
}

struct item {
    int prior, cnt;
    item * l, * r;

    item( ) : prior( random( )), cnt( 1 ), l( nullptr ), r( nullptr ) {};
};

typedef item * pitem;

int cnt( pitem t ) {
    return t ? t->cnt : 0;
}

void upd_cnt( pitem t ) {
    if ( t )
        t->cnt = 1 + cnt( t->l ) + cnt( t->r );
}


void split( pitem t, int key, pitem & l, pitem & r, int add = 0 ) {
    if ( !t )
        return void( l = r = nullptr );
    int curr_st = add + cnt( t->l );
    if ( key <= curr_st )
        split( t->l, key, l, t->l, add ), r = t;
    else
        split( t->r, key, t->r, r, add + 1 + cnt( t->l )), l = t;
    upd_cnt( t );
}

void merge( pitem & t, pitem l, pitem r ) {
    if ( !l || !r )
        t = l ? l : r;
    else if ( l->prior > r->prior )
        merge( l->r, l->r, r ), t = l;
    else
        merge( r->l, l, r->l ), t = r;
    upd_cnt( t );
}

pitem tree = nullptr;

int t;

vector < pair < int, int > > adj[maxn];

int ban[maxn], used[maxn], clr[maxn];


inline void dfs( int v, int c ) {
    used[v] = 1;
    clr[v] = c;
    for ( pair < int, int > e :adj[v] ) {
        if ( used[e.first] ) continue;
        dfs( e.first, c == 1 ? 0 : 1 );
    }
}

void input( ) {
    cin >> t;
}

void solve( ) {
    for ( int o = 0; o < t; o++ ) {
        int n, m;
        cin >> n >> m;
        fill( ban, ban + 3 * n + 1, 0 );
        fill( clr, clr + 3 * n + 1, 0 );

        for ( int i = 0; i <= 3 * n; i++ ) {
            adj[i].clear( );
        }

        int from, to;

        for ( int i = 1; i <= m; i++ ) {
            cin >> from >> to;
            adj[from].push_back( {to, i} );
            adj[to].push_back( {from, i} );
        }

        fill( used, used + 3 * n + 1, 0 );
        for ( int i = 1; i <= 3 * n; i++ ) {
            if ( !used[i] ) dfs( i, 0 );
        }


        vector < int > edges, vertexes;

        for ( int i = 1; i <= 3 * n; i++ ) {
            if ( ban[i] ) continue;
            for ( pair < int, int > e:adj[i] ) {
                if ( ban[e.first] ) continue;
                if ( clr[e.first] == clr[i] ) {
                    ban[i] = 1;
                    ban[e.first] = 1;
                    edges.push_back( e.second );
                    break;
                }
            }
            if ( !ban[i] )vertexes.push_back( i );
        }

        for ( int i = 1; i <= 3 * n; i++ ) {
            if ( ban[i] ) continue;
            for ( pair < int, int > e:adj[i] ) {
                if ( ban[e.first] ) continue;
                ban[i] = 1;
                ban[e.first] = 1;
                edges.push_back( e.second );
                break;
            }
        }

        if ( edges.size( ) >= n ) {
            cout << "Matching" << endl;
            for ( int i = 0; i < n; i++ ) {
                cout << edges[i] << " ";
            }
            cout << endl;
            continue;
        }

        if ( vertexes.size( ) >= n ) {
            cout << "IndSet" << endl;
            for ( int i = 0; i < n; i++ ) {
                cout << vertexes[i] << " ";
            }
            cout << endl;
            continue;
        }

        cout << "Impossible" << endl;


    }

}

int32_t main( ) {
    IOS
    input( );
    solve( );
    return 0;

}
