import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
    n, m = map(int, input().split())
    v = set(range(1, 3 * n + 1))
    e = []
    for i in range(1, m + 1):
        a, b = map(int, input().split())
        if a in v and b in v:
            e.append(i)
            v.remove(a)
            v.remove(b)
    if len(e) >= n:
        print('Matching')
        print(*e[:n])
    else:
        print('IndSet')
        print(*list(v)[:n])
