T = int(input())
for _ in range(T):
    n, m = map(int, input().split())
    v = [True] * (3 * n + 1)
    e = [0] * n
    ptr = 0
    ok = False
    for i in range(1, m + 1):
        a, b = map(int, input().split())
        if v[a] and v[b]:
            e[ptr] = i
            ptr += 1
            v[a] = False
            v[b] = False
        if ptr == n:
            print('Matching')
            print(*e)
            ok = True
            break
    if ok:
        continue
    print('IndSet')
    cnt = 0
    for i in range(1, n * 3 + 1):
        if v[i]:
            print(i, end=' ')
            cnt += 1
        if cnt == n:
            print()
            break
