#!/usr/bin/env python3
from collections import defaultdict, Counter

n, edges, stack, seen, todo = int(input()), defaultdict(dict), [], set(), [[1]]
for i in range(n):
    u, v, h = map(int, input().split())
    edges[u][v] = (h, i)
    edges[v][u] = (h, i)

if any(any(c > 2 for c in Counter(h for h, _ in edges[u].values()).values()) for u in edges):
    print("impossible"), exit()

while True:
    curr = todo[-1].pop()
    if curr in seen:
        break
    stack.append(curr)
    seen.add(curr)
    todo.append([x for x in edges[curr].keys() if len(stack) == 1 or stack[-2] != x])
    while todo and not todo[-1]:
        if not stack:
            print("impossible"), exit()
        todo.pop()
        seen.remove(stack.pop())

cycle = [curr]
while stack:
    u = stack.pop()
    if u == curr: break
    cycle.append(u)
while stack:
    seen.remove(stack.pop())


def find_numbering(st):
    new_seen = set(seen)
    ans = []
    for u, v in zip(st, [*st[1:], st[0]]):
        h, i = edges[u][v]
        ans.append((i, u))
        todo = [(v, h)]
        while todo:
            curr, h2 = todo.pop()
            new_seen.add(curr)
            neighs = [(neigh, t) for neigh, t in edges[curr].items() if neigh not in new_seen]
            if any(c > 1 for c in Counter([*((h3 for _, (h3, _) in neighs)), *([h] if curr == v else [])]).values()):
                return False
            for neigh, (h3, i3) in neighs:
                ans.append((i3, neigh))
                todo.append((neigh, h3))
    return " ".join(str(u) for i, u in sorted(ans))


print(find_numbering(cycle) or find_numbering(cycle[::-1]) or "impossible")
