import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def main():

    t = int(input())
    from collections  import deque
    import copy
    for _ in range(t):
        n, m = map(int, input().split())
        toid = {}
        g = [[] for i in range(3*n)]
        ind = [0]*(3*n)
        for i in range(m):
            u, v = map(int, input().split())
            u, v = u-1, v-1
            g[u].append(v)
            g[v].append(u)
            ind[v] += 1
            ind[u] += 1
            toid[(u, v)] = i
            toid[(v, u)] = i

        q = deque([])
        visit = [False]*(3*n)
        m = min(ind)
        for i in range(3*n):
            if ind[i] == m:
                q.append(i)
                visit[i] = True
        S = set()
        ban = set()
        while q:
            v = q.popleft()
            if v not in ban:
                S.add(v)
                for u in g[v]:
                    ban.add(u)
            for u in g[v]:
                if not visit[u]:
                    q.append(u)
                    visit[u] = True
        #print(S)
        if len(S) >= n:
            S = list(S)
            S = S[0:n]
            S = [i+1 for i in S]
            print('IndSet')
            print(*S)
            continue

        q = deque([])
        visit = [False]*(3*n)
        m = max(ind)
        for i in range(3*n):
            if ind[i] == m:
                q.append(i)
                visit[i] = True
        #print(q)
        M = set()
        ban = set()
        while q:
            v = q.popleft()
            for u in g[v]:
                j = toid[(u, v)]
                if u not in ban and v not in ban:
                    M.add(j)
                    ban.add(u)
                    ban.add(v)
                if not visit[u]:
                    q.append(u)
                    visit[u] = True
        #print(M)
        if len(M) >= n:
            M = list(M)
            M = M[0:n]
            M = [i+1 for i in M]
            print('Matching')
            print(*M)
            continue
        print('Impossible')

if __name__ == '__main__':
    main()
