During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.

Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of the student that stands in line directly in front of him, and the student that stands in line directly behind him. If no one stands before or after a student (that is, he is the first one or the last one), then he writes down number 0 instead (in Berland State University student IDs are numerated from 1).

After that, all the students went about their business. When they returned, they found out that restoring the queue is not such an easy task.

Help the students to restore the state of the queue by the numbers of the student ID's of their neighbors in the queue.


-----Input-----

The first line contains integer n (2 ≤ n ≤ 2·10^5) — the number of students in the queue. 

Then n lines follow, i-th line contains the pair of integers a_{i}, b_{i} (0 ≤ a_{i}, b_{i} ≤ 10^6), where a_{i} is the ID number of a person in front of a student and b_{i} is the ID number of a person behind a student. The lines are given in the arbitrary order. Value 0 is given instead of a neighbor's ID number if the neighbor doesn't exist.

The ID numbers of all students are distinct. It is guaranteed that the records correspond too the queue where all the students stand in some order.


-----Output-----

Print a sequence of n integers x_1, x_2, ..., x_{n} — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one.


-----Examples-----
Input
4
92 31
0 7
31 0
7 141

Output
92 7 31 141 



-----Note-----

The picture illustrates the queue for the first sample. [Image]

Difficulty: MEDIUM

Solutions:
from sys import stdin
n = int(input())
graph = {}
for _ in range(1, n + 1):
	(ai, bi) = input().split()
	graph[ai] = bi
ans = [0] * n
ans[0] = (set(graph.keys()) - set(graph.values())).pop()
ans[1] = graph['0']
for i in range(2, n):
	ans[i] = graph[ans[i - 2]]
print(*ans)


n = int(input())
graph = dict((input().split() for _ in range(n)))
ans = [None] * n
values = set(graph.values())
ans[0] = next((k for k in graph if k not in values))
ans[1] = graph['0']
for i in range(2, n):
	ans[i] = graph[ans[i - 2]]
print(*ans)


n = int(input())
graph = {}
(A, B) = (set(), set())
for _ in range(1, n + 1):
	(ai, bi) = input().split()
	graph[ai] = bi
	A.add(ai)
	B.add(bi)
ans = [0] * n
ans[0] = (A - B).pop()
ans[1] = graph['0']
for i in range(2, n):
	ans[i] = graph[ans[i - 2]]
print(*ans)


import sys
sys.setrecursionlimit(10000000)
n = int(input())
father = [i for i in range(n + 1)]
children = [i for i in range(n + 1)]
i = 0
imap = 1
mapping = {'0': 0, 0: '0'}
while i < n:
	(a, b) = [i for i in input().split()]
	if not a in mapping:
		mapping[a] = imap
		mapping[imap] = a
		imap += 1
	if not b in mapping:
		mapping[b] = imap
		mapping[imap] = b
		imap += 1
	father[mapping[b]] = mapping[a]
	if b != 0:
		children[mapping[a]] = mapping[b]
	else:
		children[mapping[a]] = -1
	i += 1
i = 0
while father[i] != i:
	i += 1
queue = [mapping[i]]
first = i
i = 0
while father[i] != 0:
	i += 1
queue.append(mapping[i])
father[i] = -1
second = i
i = 0
while i < n - 2:
	if i % 2 == 0:
		first = children[first]
		queue.append(mapping[first])
	else:
		second = children[second]
		queue.append(mapping[second])
	i += 1
print(' '.join(queue))


from sys import stdin
test_lines = map(str.strip, stdin.readlines())
n = int(next(test_lines))
graph = {}
(a, b) = (set(), set())
for _ in range(1, n + 1):
	(ai, bi) = next(test_lines).split()
	graph[ai] = bi
	a.add(ai)
	b.add(bi)
ans = [(a - b).pop(), graph['0']]
for i in range(2, n):
	ans.append(graph[ans[i - 2]])
print(*ans)


(u, v, n) = ({}, {}, int(input()))
for i in range(n):
	(a, b) = input().split()
	u[a] = b
	v[b] = a
(x, y) = (u['0'], v['0'])
if n & 1:
	for y in v:
		if not y in u:
			break
(a, b) = ([x], [y])
k = n // 2
for i in range(k - 1):
	(x, y) = (u[x], v[y])
	a.append(x)
	b.append(y)
if n & 1:
	b.append(v[y])
b.reverse()
t = []
for i in range(k):
	t.append(b[i])
	t.append(a[i])
if n & 1:
	t.append(b[k])
print(' '.join(t))


n = int(input())
d = {}
f_list = []
s = set()
for i in range(n):
	(first, second) = map(str, input().split(' '))
	d[first] = second
	f_list.append(first)
	s.add(second)
first = ''
for x in f_list:
	if x not in s:
		first = x
		break
answer = []
answer.append(first)
answer.append(d['0'])
for i in range(n - 2):
	counter = i + 2
	answer.append(d[answer[counter - 2]])
print(' '.join(answer))


n = int(input())
graph = dict([input().split() for _ in range(n)])
ans = [0] * n
ans[0] = (set(graph.keys()) - set(graph.values())).pop()
ans[1] = graph['0']
for i in range(2, n):
	ans[i] = graph[ans[i - 2]]
print(*ans)


from sys import stdin
test_lines = map(str.strip, stdin.readlines())
n = int(next(test_lines))
graph = {}
for _ in range(1, n + 1):
	(ai, bi) = next(test_lines).split()
	graph[ai] = bi
ans = [-1] * n
first = (set(graph.keys()) - set(graph.values())).pop()
ans[0] = first
ans[1] = graph['0']
for i in range(2, n):
	ans[i] = graph[ans[i - 2]]
print(*ans)


(ab, ba, n) = ({}, {}, int(input()))
res = [None] * n
for _ in range(n):
	(a, b) = input().split()
	(ab[a], ba[b]) = (b, a)
x = '0'
for i in range(1, n, 2):
	res[i] = x = ab[x]
if n & 1:
	n += 1
	for x in ba:
		if x not in ab:
			ba['0'] = x
			break
x = '0'
for i in range(n - 2, -1, -2):
	res[i] = x = ba[x]
print(' '.join(res))


n = int(input())
st = {}
fn = {}
for i in range(n):
	(a, b) = input().split()
	st[a] = b
	fn[b] = a
p = [None] * n
z = '0'
for i in range(1, n, 2):
	p[i] = st[z]
	z = st[z]
if n % 2 == 1:
	n += 1
	for u in fn:
		if u not in st:
			fn['0'] = u
			break
z = '0'
for i in range(n - 2, -1, -2):
	p[i] = fn[z]
	z = fn[z]
print(' '.join(p))