There are $n$ kids, numbered from $1$ to $n$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $p_1$, $p_2$, ..., $p_n$ (all these numbers are from $1$ to $n$ and are distinct, so $p$ is a permutation). Let the next kid for a kid $p_i$ be kid $p_{i + 1}$ if $i < n$ and $p_1$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $x$) and the next kid for $x$. Each kid told you which kids he/she remembered: the kid $i$ remembered kids $a_{i, 1}$ and $a_{i, 2}$. However, the order of $a_{i, 1}$ and $a_{i, 2}$ can differ from their order in the circle. [Image] Example: 5 kids in a circle, $p=[3, 2, 4, 1, 5]$ (or any cyclic shift). The information kids remembered is: $a_{1,1}=3$, $a_{1,2}=5$; $a_{2,1}=1$, $a_{2,2}=4$; $a_{3,1}=2$, $a_{3,2}=4$; $a_{4,1}=1$, $a_{4,2}=5$; $a_{5,1}=2$, $a_{5,2}=3$. 

You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.

If you are Python programmer, consider using PyPy instead of Python when you submit your code.


-----Input-----

The first line of the input contains one integer $n$ ($3 \le n \le 2 \cdot 10^5$) — the number of the kids.

The next $n$ lines contain $2$ integers each. The $i$-th line contains two integers $a_{i, 1}$ and $a_{i, 2}$ ($1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$) — the kids the $i$-th kid remembered, given in arbitrary order.


-----Output-----

Print $n$ integers $p_1$, $p_2$, ..., $p_n$ — permutation of integers from $1$ to $n$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists.


-----Examples-----
Input
5
3 5
1 4
2 4
1 5
2 3

Output
3 2 4 1 5 

Input
3
2 3
3 1
1 2

Output
3 1 2

Difficulty: MEDIUM_HARD
Tags: Implementation

Starter code:

Solutions:
from sys import stdin
n = int(stdin.readline().strip())
if n == 3:
	print('1 2 3')
	return
adj = [(0, 0)]
for i in range(n):
	(a, b) = list(map(int, stdin.readline().strip().split()))
	adj.append((a, b))
s = []
x = 1
while len(s) < n:
	if adj[x][0] in adj[adj[x][1]]:
		s.append(adj[x][1])
		s.append(adj[x][0])
		x = adj[x][0]
	if adj[x][1] in adj[adj[x][0]]:
		s.append(adj[x][0])
		s.append(adj[x][1])
		x = adj[x][1]
print(*s[0:n])


n = int(input())
in_ = []
for i in range(n):
	(ai1, ai2) = map(int, input().split())
	in_.append((ai1, ai2))
if in_[0][0] in in_[in_[0][1] - 1]:
	(l, r) = (in_[0][1], in_[0][0])
else:
	(l, r) = (in_[0][0], in_[0][1])
for i in range(n):
	print(r, end=' ')
	if in_[l - 1][0] != r:
		(l, r) = (r, in_[l - 1][0])
	else:
		(l, r) = (r, in_[l - 1][1])
print()


n = int(input())
a = [[] for i in range(n + 1)]
for i in range(n):
	a[i + 1] = list(map(int, input().split()))
ans = [1]
i = 1
while len(ans) < n:
	if a[i][1] in a[a[i][0]] and a[i][0] != 1:
		ans.append(a[i][0])
		i = a[i][0]
	else:
		ans.append(a[i][1])
		i = a[i][1]
print(*ans)


from sys import stdin
n = int(input())
if n == 3:
	print('3 1 2')
else:
	pairs = [(0, 0)]
	for i in range(n):
		(a, b) = [int(x) for x in stdin.readline().split()]
		pairs.append((a, b))
	ans = []
	j = 1
	while len(ans) < n:
		p = pairs[j]
		if set([p[0]]) & set(pairs[p[1]]) != set():
			ans.append(p[1])
			ans.append(p[0])
			j = p[0]
		if set([p[1]]) & set(pairs[p[0]]) != set():
			ans.append(p[0])
			ans.append(p[1])
			j = p[1]
	print(*ans[0:n])


from sys import stdin
n = int(stdin.readline().strip())
arr = []
for _ in range(n):
	arr.append(list(map(int, stdin.readline().split())))
ans = []
last = 1
ans.append(last)
while len(ans) < n:
	(first, second) = arr[last - 1]
	if second in arr[first - 1]:
		ans.append(first)
		ans.append(second)
		last = second
	else:
		ans.append(second)
		ans.append(first)
		last = first
for i in range(n):
	print(ans[i], end=' ')


n = int(input())
A = [0] + [[int(i) for i in input().split()] for j in range(n)]
ans = [1]
i = 1
while len(ans) < n:
	if A[i][1] in A[A[i][0]] and A[i][0] != 1:
		ans.append(A[i][0])
		i = A[i][0]
	else:
		ans.append(A[i][1])
		i = A[i][1]
print(*ans)


n = int(input())
nums = {}
for i in range(1, n + 1):
	t = list(map(int, input().split()))
	nums[i] = t

def check(a, b, n, nums):
	output = []
	nxt = None
	while len(output) != n:
		if nums[a][0] == b:
			nxt = nums[a][1]
		elif nums[a][1] == b:
			nxt = nums[a][0]
		else:
			return
		output.append(nxt)
		a = b
		b = nxt
	print(*output)
	exit()
check(1, nums[1][0], n, nums)
check(1, nums[1][1], n, nums)


n = int(input())
P = [0]
count = n
ans = [1]
i = 1
while count:
	P.append(list(map(int, input().split())))
	count = count - 1
for t in range(n - 1):
	if P[i][0] != 1 and P[i][1] in P[P[i][0]]:
		ans.append(P[i][0])
		i = P[i][0]
	else:
		ans.append(P[i][1])
		i = P[i][1]
print(*ans)


n = int(input())
memories = []
for i in range(n):
	memories.append(tuple(map(int, input().split())))
p = [1]
while len(p) < n:
	i = p[-1]
	(x, y) = memories[i - 1]
	if y in memories[x - 1]:
		p.append(x)
		p.append(y)
	else:
		p.append(y)
		p.append(x)
if len(p) > n:
	p.pop()
print(*p)


n = int(input())
A = []
S = [1]
for _ in range(n):
	A.append([int(x) for x in input().split(' ')])
for _ in range(n // 2):
	(x, y) = (A[S[-1] - 1][0], A[S[-1] - 1][1])
	if A[x - 1][0] != y and A[x - 1][1] != y:
		(x, y) = (y, x)
	if len(S) < n:
		S.append(x)
	if len(S) < n:
		S.append(y)
print(' '.join([str(x) for x in S]))


n = int(input())
if n == 3:
	print(1, 2, 3)
	exit()
cnt = [0] * (n + 1)
ans = [1]
used = [False] * (n + 1)
for i in range(1, n + 1):
	(a, b) = list(map(int, input().split()))
	cnt[i] = [a, b]
for i in range(n - 1):
	if cnt[ans[-1]][0] in cnt[cnt[ans[-1]][1]] and (not used[cnt[ans[-1]][1]]):
		ans.append(cnt[ans[-1]][1])
	else:
		ans.append(cnt[ans[-1]][0])
print(' '.join(map(str, ans)))


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = []
for _ in range(n):
	a.append(tuple(int_array()))
ans = [1]
while len(ans) != n:
	if len(ans) == n + 1:
		ans.pop()
		continue
	(x, y) = a[ans[-1] - 1]
	if x in a[y - 1]:
		ans.append(y)
		ans.append(x)
	else:
		ans.append(x)
		ans.append(y)
print(*ans)


import sys
input = sys.stdin.readline
n = int(input())
l = [1]
d = {}
k = 1
for i in range(1, n + 1):
	(a, b) = map(int, input().split())
	d[i] = [a, b]
if n < 4:
	print('1 2 3')
else:
	while len(l) != n:
		(a, b) = d[k]
		if a in d[b]:
			l.append(b)
			k = b
		else:
			l.append(a)
			k = a
	print(*l)


import sys
from io import StringIO
from atexit import register
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

def Rd(f=int):
	return [f(x) for x in input().split()]

def Debug(x):
	print('\x1b[0;31m{}\x1b[0m'.format(x), file=sys.stderr)

def PrintFloats(arr):
	return ' '.join(('{:.10f}'.format(x) for x in arr))
n = int(input())
pairs = [Rd(int) for _ in range(n)]
ans = [1]
while len(ans) < n:
	cur = ans[-1]
	(u, v) = pairs[cur - 1]
	if u in pairs[v - 1]:
		ans += [v, u]
	else:
		ans += [u, v]
print(*ans[:n])


import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
know = [None for _ in range(n + 1)]
for i in range(1, n + 1):
	l = list(map(int, input().split()))
	know[i] = l
num_to_index = [None] * (n + 1)
res = [None] * n
done = [False] * (n + 1)
num_to_index[1] = 0
res[0] = 1
done[1] = True
dq = deque([1])
while dq:
	node = dq.popleft()
	node_pos = num_to_index[node]
	(k1, k2) = (know[node][0], know[node][1])
	if num_to_index[k1] == num_to_index[k2] == None:
		if k1 in know[k2]:
			k2_pos = (node_pos + 1) % n
			k1_pos = (node_pos + 2) % n
		else:
			k2_pos = (node_pos + 2) % n
			k1_pos = (node_pos + 1) % n
		res[k1_pos] = k1
		num_to_index[k1] = k1_pos
		res[k2_pos] = k2
		num_to_index[k2] = k2_pos
	elif num_to_index[k1] == None or num_to_index[k2] == None:
		k = k1 if num_to_index[k1] == None else k2
		if not res[(node_pos + 1) % n]:
			res[(node_pos + 1) % n] = k
			num_to_index[k] = (node_pos + 1) % n
		else:
			res[(node_pos + 2) % n] = k
			num_to_index[k] = (node_pos + 2) % n
	if not done[k1]:
		dq.append(k1)
		done[k1] = True
	if not done[k2]:
		dq.append(k2)
		done[k2] = True
print(*res)


import sys

def fprint(x):
	print(x, flush=True)

def qprint(x):
	sys.stdout.write(str(x) + '\n')

def input():
	return sys.stdin.readline()
N = int(input())
belongs_in = dict()
belongs_to_this = dict()
for l in range(1, N + 1):
	(n, m) = map(int, input().split())
	belongs_to_this[l] = [n, m]
	belongs_in.setdefault(n, [])
	belongs_in.setdefault(m, [])
	belongs_in[n].append(l)
	belongs_in[m].append(l)
to_print = []
to_print.append(1)
for ele in belongs_in[1]:
	for num in belongs_to_this[ele]:
		if num in belongs_to_this[1]:
			to_print.append(num)
while len(to_print) < N:
	focus = to_print[len(to_print) - 2]
	for ele in belongs_to_this[focus]:
		if ele != to_print[len(to_print) - 1] and ele != to_print[len(to_print) - 2]:
			to_print.append(ele)
print(' '.join(map(str, to_print)))


n = int(input())
L = []
for _ in range(n):
	(x, y) = [int(x) - 1 for x in input().split()]
	L.append((x, y))
if n == 3:
	print('1 2 3')
else:
	order = ['1']
	count = 1
	current = 0
	while count < n:
		(a, b) = L[current]
		if b in L[a]:
			order.append(str(a + 1))
			count += 1
			current = a
		else:
			order.append(str(b + 1))
			count += 1
			current = b
	print(' '.join(order))


def func():
	n = int(input())
	g = [()] + [set(map(int, input().split())) for i in range(n)]
	if n == 3:
		print(1, 2, 3)
		return None
	xor = [1]
	for i in range(n - 1):
		(x, y) = (j for j in g[xor[-1]])
		if x in g[y]:
			xor.append(y)
		elif y in g[x]:
			xor.append(x)
	print(' '.join(map(str, xor)))
func()


def b(v, n):
	(bv, bs) = ([], set())
	t = 0
	for c in range(n):
		bv.append(t + 1)
		bs.add(t)
		(f, s) = v[t]
		t = s if f in v[s] and s not in bs else f
	print(*bv)
n = int(input())
v = []
for c in range(n):
	(f, s) = [int(d) - 1 for d in input().split()]
	v.append((f, s))
b(v, n)


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
if n > 3:
	b = [0] * (n + 1)
	for i in range(n):
		(x, y) = a[i]
		if y in a[x - 1]:
			b[i + 1] = x
		elif x in a[y - 1]:
			b[i + 1] = y
		else:
			print(-1)
			break
	else:
		c = [0]
		x = 1
		for _ in range(n):
			c += (x,)
			x = b[x]
		print(*c[1:])
else:
	print(1, 2, 3)


n = int(input())
arr = [-1]
a = [[]]
for i in range(n):
	a.append(list(map(int, input().split())))
arr.append(1)
if a[1][0] not in a[a[1][1]]:
	arr.append(a[1][0])
	arr.append(a[1][1])
else:
	arr.append(a[1][1])
	arr.append(a[1][0])
while len(arr) < n + 1:
	if a[arr[-2]][0] != arr[-1]:
		arr.append(a[arr[-2]][0])
	else:
		arr.append(a[arr[-2]][1])
for i in range(1, len(arr) - 1):
	print(arr[i], end=' ')
print(arr[n])


import sys
input = sys.stdin.readline
n = int(input())
P = [list(map(int, input().split())) for i in range(n)]
(x, y) = P[0]
if y in P[x - 1]:
	print(1, x, end=' ')
	n = x
	nn = y
else:
	print(1, y, end=' ')
	n = y
	nn = x
while nn != 1:
	(k, u) = P[n - 1]
	print(nn, end=' ')
	if k == nn:
		(n, nn) = (nn, u)
	else:
		(n, nn) = (nn, k)


from sys import stdin
input = stdin.buffer.readline
n = int(input())
d = {}
for i in range(1, n + 1):
	(x, y) = map(int, input().split())
	d[i] = (x, y)
ans = [1]
while len(ans) < n:
	x = ans[-1]
	a = d[x][0]
	b = d[x][1]
	if b in d[a]:
		ans.append(a)
		ans.append(b)
	else:
		ans.append(b)
		ans.append(a)
if len(ans) > n:
	x = ans.pop()
	y = ans.pop()
	if x == 1:
		ans.append(y)
	else:
		ans.append(x)
print(*ans)


n = int(input())
if n is 3:
	print(1, 2, 3)
	exit(0)
a = [0] * (n + 1)
for i in range(n):
	a[i + 1] = [int(t) for t in input().split()]
r = [0] * n
r[0] = 1
for i in range(1, n):
	(p, q) = a[r[i - 1]]
	r[i] = p if q in a[p] else q
print(*r)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
if n == 3:
	ans = [1, 2, 3]
else:
	a = [None] + [li() for i in range(n)]
	ans = []
	i = 1
	while 1:
		ans.append(i)
		j = a[i][0]
		if a[i][1] not in a[j]:
			j = a[i][1]
		i = j
		if i == 1:
			break
print(*ans)


import sys
input = sys.stdin.readline
N = int(input())
aN = [None] * N
for i in range(N):
	aN[i] = list(map(int, input().split()))
	aN[i][0] -= 1
	aN[i][1] -= 1
nxt = 0
ans = [nxt]
for _ in range(N - 1):
	if aN[nxt][1] in aN[aN[nxt][0]]:
		nxt = aN[nxt][0]
	elif aN[nxt][0] in aN[aN[nxt][1]]:
		nxt = aN[nxt][1]
	ans.append(nxt)
for i in range(len(ans)):
	ans[i] += 1
if N == 3:
	print(1, 2, 3)
else:
	print(*ans)


n = int(input())
R = lambda : map(int, input().split())
l = [0]
for i in range(n):
	(x, y) = R()
	l.append([x, y])
r = [1] * n
i = 0
while i < n - 2:
	p = l[r[i]][0]
	q = l[r[i]][1]
	i += 1
	if q in l[p]:
		r[i] = p
	else:
		r[i] = q
p = l[r[n - 2]][0]
q = l[r[n - 2]][1]
if p != 1:
	r[n - 1] = p
else:
	r[n - 1] = q
print(*r)


from sys import stdin, stdout
import collections
import math
N = int(input())
data = [[0, 0]]
for i in range(N):
	(A, B) = [int(x) for x in stdin.readline().split()]
	data.append([A, B])
if N == 3:
	print(1, data[1][0], data[1][1], sep=' ')
else:
	cur = 1
	k = 1
	while k <= N:
		print(cur, end=' ')
		A = data[cur][0]
		B = data[cur][1]
		if A in data[A] or A in data[B]:
			cur = B
		elif B in data[A] or B in data[B]:
			cur = A
		k += 1


n = int(input())
nextp = dict()
for i in range(1, n + 1):
	nextp[i] = tuple(map(int, input().split()))

def work(arr, queue, added):
	while len(queue) > 0:
		(x, idx) = queue.pop(0)
		for nbr in nextp[x]:
			if added[nbr] == 1:
				continue
			if len(arr) == idx + 1:
				arr.append(nbr)
				added[nbr] = 1
				queue.append((nbr, idx + 1))
			elif len(arr) == idx + 2:
				arr.append(nbr)
				added[nbr] = 1
				queue.append((nbr, idx + 2))
			else:
				return False
	return True
arr = [1]
arr.append(nextp[1][0])
arr.append(nextp[1][1])
queue = [(nextp[1][0], 1), (nextp[1][1], 2)]
added = [0] * (n + 1)
added[1] = added[nextp[1][0]] = added[nextp[1][1]] = 1
if work(arr, queue, added):
	case1 = True
	for i in range(0, n - 2):
		if arr[i + 1] in nextp[arr[i]] and arr[i + 2] in nextp[arr[i]]:
			continue
		else:
			case1 = False
			break
	if case1 and arr[n - 1] in nextp[arr[n - 2]] and (arr[0] in nextp[arr[n - 2]]) and (arr[0] in nextp[arr[n - 1]]) and (arr[1] in nextp[arr[n - 1]]):
		print(*arr)
		exit(0)
arr = [1]
arr.append(nextp[1][1])
arr.append(nextp[1][0])
queue = [(nextp[1][1], 1), (nextp[1][0], 2)]
added = [0] * (n + 1)
added[1] = added[nextp[1][0]] = added[nextp[1][1]] = 1
work(arr, queue, added)
print(*arr)


import sys
n = int(sys.stdin.readline())
l = []
dct = {}
for i in range(n):
	x = list(map(int, sys.stdin.readline().split()))
	dct[str(x)] = 0
	l.append(x)
this = 1
nxt = -1
nxt2nxt = -1
(x, y) = (l[0][0], l[0][1])
if str([1, y]) in dct or str([y, 1]) in dct:
	nxt = y
	nxt2nxt = x
else:
	nxt = x
	nxt2nxt = y
for i in range(n):
	sys.stdout.write(str(this) + ' ')
	this = nxt
	nxt = nxt2nxt
	if l[this - 1][0] == nxt:
		nxt2nxt = l[this - 1][1]
	else:
		nxt2nxt = l[this - 1][0]


n = int(input())
a = []
b = []
if n == 3:
	print('1 2 3')
else:
	for i in range(n):
		(x, y) = map(int, input().split())
		a.append(x)
		b.append(y)
	real = [1]
	for i in range(n - 1):
		(c, d) = (a[real[-1] - 1], b[real[-1] - 1])
		if d == a[c - 1] or d == b[c - 1]:
			real.append(c)
		else:
			real.append(d)
	out = ''
	for guy in real:
		out += str(guy) + ' '
	print(out)


N = int(input().strip())
if N == 3:
	print(1, 2, 3)
else:
	g = {}
	for i in range(1, 1 + N):
		g[i] = list(map(int, input().strip().split()))
	q = [1]
	for i in range(N - 1):
		nexts = g[q[-1]]
		q.append(nexts[0] if nexts[1] in g[nexts[0]] else nexts[1])
	print(*q)


def solve_problem(kids_count, triplets_list):
	for i in range(kids_count):
		[idx, a1, a2] = triplets_list[i]
		if triplets_list[a1 - 1][1] != a2 and triplets_list[a1 - 1][2] != a2:
			swap = triplets_list[i][1]
			triplets_list[i][1] = triplets_list[i][2]
			triplets_list[i][2] = swap
	output = [0] * (kids_count + 2)
	(output[0], output[1], output[2]) = triplets_list[0]
	for k in range(1, kids_count // 2):
		l = k * 2
		(output[l], output[l + 1], output[l + 2]) = triplets_list[output[l] - 1]
	return output[:kids_count]
kids_count = int(input())
links = []
for i in range(kids_count):
	links.append([i + 1] + list(map(int, input().split(' '))))
sol = solve_problem(kids_count, links)
print(' '.join(map(str, sol)))


n = int(input())
p = []
for i in range(n):
	(x, y) = map(int, input().split())
	p.append([x - 1, y - 1])
ans = []
k = 0
i = 0
while 1:
	if p[i][0] in p[p[i][1]]:
		ans += [i, p[i][1]]
		i = p[i][0]
	else:
		ans += [i, p[i][0]]
		i = p[i][1]
	k += 2
	if k >= n:
		break
for i in range(n):
	print(ans[i] + 1, end=' ')


n = int(input())
lis = {}
check = []
data = [tuple(map(int, input().split())) for _ in range(n)]
for i in range(n):
	lis[i + 1, data[i][0]] = 1
	lis[i + 1, data[i][1]] = 1
	check.append((data[i][0], data[i][1]))
	check.append((data[i][1], data[i][0]))
adm = {}
for m in check:
	if m in lis:
		if m[1] not in adm or (m[1] in adm and adm[m[1]] != m[0]):
			adm[m[0]] = m[1]
sol = []
for m in adm:
	sol.append(m)
	break
while len(sol) < n:
	if sol[-1] in adm:
		sol.append(adm[sol[-1]])
	else:
		for (k, v) in adm.items():
			if sol[-1] == v and k not in sol:
				sol.append(k)
				break
print(' '.join(map(str, sol)))


from collections import defaultdict
n = int(input())
x = [(0, 0)]
for i in range(n):
	x.append(tuple(map(int, input().split())))
neigh = defaultdict(list)
for i in x[1:]:
	neigh[i[0]].append(i[1])
	neigh[i[1]].append(i[0])
res = [1]
s = 1
visited = [False] * (n + 1)
while True:
	visited[s] = True
	if x[s][0] in neigh[s] and (not visited[x[s][0]]):
		res.append(x[s][0])
		s = x[s][0]
	else:
		res.append(x[s][1])
		s = x[s][1]
	if len(res) == n:
		break
res_new = [str(x) for x in res]
print(' '.join(res_new))


n = int(input())
seq = (i for i in range(1, n + 1))
d = dict.fromkeys(seq)
d
for i in range(1, n + 1):
	d[i] = list(map(int, input().rstrip().split()))
start = [1]
current = 1
i = 0
while i < n:
	nextpair = d[current]
	if nextpair[0] in d[nextpair[1]]:
		start.append(nextpair[1])
		start.append(nextpair[0])
		current = nextpair[0]
	else:
		start.append(nextpair[0])
		start.append(nextpair[1])
		current = nextpair[1]
	i += 2
print(*start[0:n])


from collections import deque
n = int(input())
d = {}
l = {}
for i in range(n):
	c = i + 1
	l[c] = [-1, -1]
	(x, y) = map(int, input().split())
	if x in d:
		d[x].append(c)
	else:
		d[x] = [c]
	if y in d:
		d[y].append(c)
	else:
		d[y] = [c]
if n == 3:
	for i in d:
		e = d[i]
		th = i
		if e[0] in d:
			flag = 0
			q = d[e[0]]
			for j in q:
				if j == e[1]:
					flag = 1
					break
			if flag:
				fi = e[1]
				se = e[0]
			else:
				fi = e[0]
				se = e[1]
		else:
			fi = e[0]
			se = e[1]
		l[se][0] = fi
		l[se][1] = th
		l[fi][1] = se
		l[th][0] = se
	g = -1
	f = 0
	for x in l:
		if l[x][0] == l[x][1]:
			g = x
			f = 1
			break
	if f:
		del l[g]
	ans = []
	visited = set()
	cnt = 0
	i = 1
	if f:
		if g == 1:
			i = 3
			if l[3][1] == 1:
				i = 2
	while cnt < n:
		visited.add(i)
		ans.append(i)
		cnt += 1
		if cnt == n:
			break
		i = l[i][1]
	print(*ans)
	exit()
for i in d:
	e = d[i]
	th = i
	if e[0] in d:
		flag = 0
		q = d[e[0]]
		for j in q:
			if j == e[1]:
				flag = 1
				break
		if flag:
			fi = e[1]
			se = e[0]
		else:
			fi = e[0]
			se = e[1]
	else:
		fi = e[0]
		se = e[1]
	l[se][0] = fi
	l[se][1] = th
	l[fi][1] = se
	l[th][0] = se
ans = []
visited = set()
cnt = 0
i = 1
while cnt < n:
	visited.add(i)
	ans.append(i)
	i = l[i][1]
	cnt += 1
print(*ans)


n = int(input())
g = [[0, 0]] * (n + 1)
for i in range(n):
	(a, b) = map(int, input().split())
	g[i + 1] = [a, b]
if n == 3:
	print('1 2 3')
	exit()
a = 1
o = []
while True:
	o.append(a)
	(x, y) = g[a]
	if y in g[x]:
		if x == 1:
			break
		o.append(x)
		a = y
	else:
		if y == 1:
			break
		o.append(y)
		a = x
	if a == 1:
		break
print(' '.join(map(str, o)))


n = int(input())
d = [tuple(map(int, input().split())) for _ in range(n)]
d = [(0, 0)] + d
here = 1
ret = []
if n == 3:
	print(1, 2, 3)
	exit(0)
while len(ret) != n:
	ret.append(here)
	if d[here][0] == d[d[here][1]][0] or d[here][0] == d[d[here][1]][1]:
		here = d[here][1]
	elif d[here][1] == d[d[here][0]][0] or d[here][1] == d[d[here][0]][1]:
		here = d[here][0]
for i in ret:
	print(i, end=' ')
print()


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
p = [1]
for i in range((n - 1) // 2):
	if a[p[-1] - 1][1] in a[a[p[-1] - 1][0] - 1]:
		p.append(a[p[-1] - 1][0])
		p.append(a[p[-2] - 1][1])
	else:
		p.append(a[p[-1] - 1][1])
		p.append(a[p[-2] - 1][0])
if n % 2 == 0:
	if a[p[-1] - 1][0] != p[0]:
		p.append(a[p[-1] - 1][0])
	else:
		p.append(a[p[-1] - 1][1])
print(*p)


t = int(input())
f = [0] * (t + 1)
y = [0] * t
y[0] = 1
for j in range(t):
	(n, k) = input().split()
	f[j + 1] = [int(n), int(k)]
if t == 3:
	print(1, 2, 3)
	exit()
for i in range(1, t):
	(p, q) = f[y[i - 1]]
	if q in f[p]:
		y[i] = p
	else:
		y[i] = q
for i in y:
	print(i, end=' ')


n = int(input())
x = []
for i in range(n):
	x.append(list(map(int, input().split())))
an = []
an.append(1)
if x[0][1] in x[x[0][0] - 1]:
	an.append(x[0][0])
	an.append(x[0][1])
else:
	an.append(x[0][1])
	an.append(x[0][0])
while len(an) != n:
	xx = an[-2] - 1
	yy = an[-1]
	for i in x[xx]:
		if i != yy:
			an.append(i)
print(*an)


n = int(input())
inlst = [0]
for i in range(n):
	inlst.append([int(i) for i in input().split()])
if n == 3:
	print('1 2 3')
else:
	outlst = [1]
	(p, q) = inlst[1]
	if q in inlst[p]:
		outlst.extend([p, q])
	else:
		outlst.extend([q, p])
	for i in range(n - 3):
		(p, q) = inlst[outlst[-2]]
		if p == outlst[-1]:
			outlst.append(q)
		else:
			outlst.append(p)
	print(' '.join([str(i) for i in outlst]))


n = int(input())
a = [[0, 0]]
d = {}
for _ in range(n):
	a.append(list(map(int, input().split())))
for i in range(1, n + 1):
	(first, second) = a[i]
	if i in d:
		if d[i] == first:
			d[first] = second
		elif d[i] == second:
			d[second] = first
	elif second in a[first]:
		d[i] = first
		d[first] = second
	elif first in a[second]:
		d[i] = second
		d[second] = first
r = [1]
for _ in range(n - 1):
	r.append(d[r[-1]])
print(' '.join(map(str, r)))


def main():
	n = int(input())
	kids = []
	ans = [1]
	for i in range(n):
		(a, b) = map(int, input().split())
		kids.append((a, b))
	if n == 3:
		ans = [1, 2, 3]
	else:
		(a, b) = (kids[0][0], kids[0][1])
		x1 = set([kids[0][0], kids[0][1]])
		x2 = set([kids[a - 1][0], kids[a - 1][1]])
		x3 = set([kids[b - 1][0], kids[b - 1][1]])
		p1 = x1 & x3
		p2 = x1 & x2
		for v in p1:
			if a == v:
				ans.append(b)
				ans.append(a)
			if b == v:
				ans.append(a)
				ans.append(b)
		for v in p2:
			if a == v:
				ans.append(b)
				ans.append(a)
			if b == v:
				ans.append(a)
				ans.append(b)
		index = ans[-2]
		while len(ans) != n:
			(a, b) = (kids[index - 1][0], kids[index - 1][1])
			if a == ans[-1]:
				ans.append(b)
			else:
				ans.append(a)
			index = ans[-2]
	for i in ans:
		print(i, end=' ')
main()


N = int(input())
g = []
g.append([])
for i in range(N):
	(a, b) = map(int, input().split())
	s = [a, b]
	g.append(s)
if N == 3:
	print('1 2 3')
else:
	cur = 1
	for i in range(N):
		print(cur)
		a = g[cur][0]
		b = g[cur][1]
		if g[a][0] == b or g[a][1] == b:
			cur = a
		else:
			cur = b


n = int(input())
data = []
for _ in range(n):
	data.append([int(x) for x in input().split()])
if n == 3:
	print('1 2 3')
else:
	mp = [0] * n
	for (i, x) in enumerate(data):
		(a, b) = (x[0], x[1])
		if a in data[b - 1]:
			mp[b - 1] = a
		else:
			mp[a - 1] = b
	ret = [1]
	pos = 0
	while True:
		x = mp[pos]
		ret.append(x)
		pos = x - 1
		if pos == 0:
			break
	ret = map(str, ret[:-1])
	print(' '.join(ret))


n = int(input())
arr = dict()
for i in range(n):
	arr[i + 1] = [int(x) for x in input().split()]
ans = [1]
l = 1
while l != n:
	n1 = arr[ans[-1]][0]
	n2 = arr[ans[-1]][1]
	if n2 in arr[n1]:
		ans.append(n1)
		l += 1
		if l == n:
			break
		ans.append(n2)
	else:
		ans.append(n2)
		l += 1
		if l == n:
			break
		ans.append(n1)
	l += 1
for i in ans:
	print(i, end=' ')


N = int(input())
a = []
for j in range(N):
	a.append([])
for i in range(N):
	(n, m) = map(int, input().split())
	a[i].append(n)
	a[i].append(m)
d = dict()
for j in range(1, N + 1):
	d[j] = 0
c = []
c.append(1)
d[1] = 1
n = a[0][0]
m = a[0][1]
d[n] = 1
d[m] = 1
if n in a[m - 1]:
	c.append(m)
	c.append(n)
elif m in a[n - 1]:
	c.append(n)
	c.append(m)
j = 1
p = 3
while p != N:
	n = a[c[j] - 1][0]
	m = a[c[j] - 1][1]
	if d[n] == 0:
		c.append(n)
		d[n] = 1
	elif d[m] == 0:
		c.append(m)
		d[m] = 1
	j += 1
	p += 1
print(*c)


def Interstion(lst1, lst2):
	lst = [v for v in lst1 if v in lst2]
	return lst
n = int(input())
lst = [0 for i in range(n + 1)]
dp = [0 for i in range(n + 1)]
for i in range(n):
	lst[i + 1] = list(map(int, input().split()))
dp[1] = 1
first = 1
second1 = lst[1][0]
second2 = lst[1][1]
third = Interstion(lst[first], lst[second1])
if third != []:
	dp[2] = second1
	dp[3] = third[0]
else:
	third = Interstion(lst[first], lst[second2])
	dp[2] = second2
	dp[3] = third[0]
for i in range(2, n - 1):
	dp[i + 2] = Interstion(lst[dp[i]], lst[dp[i + 1]])[0]
print(*dp[1:])


import math
import bisect
import itertools
import sys
I = lambda : sys.stdin.readline()
mod = 10 ** 9 + 7

def mindiff(a):
	b = a[:]
	b.sort()
	m = 10000000000
	for i in range(len(b) - 1):
		if b[i + 1] - b[i] < m:
			m = b[i + 1] - b[i]
	return m

def lcm(a, b):
	return a * b // math.gcd(a, b)

def merge(a, b):
	i = 0
	j = 0
	c = 0
	ans = []
	while i < len(a) and j < len(b):
		if a[i] < b[j]:
			ans.append(a[i])
			i += 1
		else:
			ans.append(b[j])
			c += len(a) - i
			j += 1
	ans += a[i:]
	ans += b[j:]
	return (ans, c)

def mergesort(a):
	if len(a) == 1:
		return (a, 0)
	mid = len(a) // 2
	(left, left_inversion) = mergesort(a[:mid])
	(right, right_inversion) = mergesort(a[mid:])
	(m, c) = merge(left, right)
	c += left_inversion + right_inversion
	return (m, c)

def is_prime(num):
	if num == 1:
		return False
	if num == 2:
		return True
	if num == 3:
		return True
	if num % 2 == 0:
		return False
	if num % 3 == 0:
		return False
	t = 5
	a = 2
	while t <= int(math.sqrt(num)):
		if num % t == 0:
			return False
		t += a
		a = 6 - a
	return True

def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1

def binsearch(arr, b, low, high):
	if low == high:
		return low
	if arr[math.ceil((low + high) / 2)] < b:
		return binsearch(arr, b, low, math.ceil((low + high) / 2) - 1)
	else:
		return binsearch(arr, b, math.ceil((low + high) / 2), high)

def ncr1(n, r):
	s = 1
	for i in range(min(n - r, r)):
		s *= n - i
		s %= mod
		s *= pow(i + 1, mod - 2, mod)
		s %= mod
	return s

def calc(n, m, r):
	s = 0
	for i in range(0, r + 1, 2):
		s += ncr1(n, i) * ncr1(m, i)
		s %= mod
	return s
n = int(input())
d = {}
for i in range(1, n + 1):
	(x, y) = map(int, input().split())
	d[i] = [x, y]
d1 = {}
if n == 3:
	exit(print(1, 2, 3))
for i in range(1, n + 1):
	if d[i][0] in d[d[i][1]]:
		d1[i] = d[i][1]
	else:
		d1[i] = d[i][0]
k = d1[1]
for i in range(n):
	print(k, end=' ')
	k = d1[k]


n = int(input())
xs = [[] for _ in range(0, n + 1)]
for i in range(1, n + 1):
	ys = list(map(int, input().split(' ')))
	xs[i] = ys
ys = ['1']
last = 1
visited = [False for _ in range(0, n + 1)]
visited[1] = True
for _ in range(0, n - 1):
	a = xs[last][0]
	b = xs[last][1]
	if b in xs[a] and (not visited[a]):
		ys.append(str(a))
		visited[a] = True
		last = a
	else:
		ys.append(str(b))
		visited[b] = True
		last = b
print(' '.join(ys))


numKids = int(input())
p = {}
for i in range(1, numKids + 1, 1):
	(a1, a2) = map(int, input().split())
	p[i] = (a1, a2)
kidOrder = [1]
i = 1
while len(kidOrder) < numKids:
	(a1, a2) = p[i]
	if a2 in p[a1] and a1 != 1:
		kidOrder.append(a1)
		i = a1
	else:
		kidOrder.append(a2)
		i = a2
print(*kidOrder)


n = int(input())
data = []
for x in range(0, n):
	data.append([int(y) - 1 for y in input().split()])

def check(parent, child):
	global data
	ans = []
	for x in range(0, n):
		nxt = -1
		if data[parent][0] == child:
			nxt = data[parent][1]
		elif data[parent][1] == child:
			nxt = data[parent][0]
		else:
			return False
		parent = child
		child = nxt
		ans.append(nxt)
	print(' '.join([str(t + 1) for t in ans]))
	exit(0)
check(0, data[0][0])
check(0, data[0][1])


n = int(input())
l = [0] + [set(map(int, input().split())) for x in range(n)]
ans = [1] if n % 2 else []
i = 1
while len(ans) < n:
	(f, s) = (x for x in l[i])
	ans.extend([f, s] if s in l[f] else [s, f])
	i = ans[-1]
print(' '.join(map(str, ans)))


from sys import stdin, stdout
input = stdin.readline
n = int(input())
a = [[]]
for _ in range(n):
	a.append(tuple(map(int, input().split())))
ans = [1]
i = 1
while len(ans) < n:
	if a[i][0] != 1 and a[i][1] in a[a[i][0]]:
		ans.append(a[i][0])
		i = a[i][0]
	else:
		ans.append(a[i][1])
		i = a[i][1]
print(*ans)


n = int(input())
circ = []
l = []
for i in range(n):
	(a1, a2) = map(int, input().split())
	a1 -= 1
	a2 -= 1
	l.append((a1, a2))
circ.append(l[0][0])
circ.append(l[0][1])
for i in range(0, n - 1):
	p = l[circ[i]]
	if circ[i + 1] not in p:
		(circ[i], circ[i + 1]) = (circ[i + 1], circ[i])
	p = l[circ[i]]
	if circ[i + 1] == p[0]:
		circ.append(p[1])
	else:
		circ.append(p[0])
for i in range(n):
	print(circ[i] + 1, end=' ')


n = int(input())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
print(1, end=' ')
i = 1
cur = 0
while i < len(arr):
	if arr[cur][1] in arr[arr[cur][0] - 1]:
		if arr[arr[cur][0] - 1][1] == arr[cur][1]:
			arr[arr[cur][0] - 1].sort(reverse=True)
		cur = arr[cur][0]
		print(cur, end=' ')
	else:
		cur = arr[cur][1]
		print(cur, end=' ')
	cur -= 1
	i += 1


n = int(input())
if n == 3:
	print('1 2 3')
	exit()
a = [0] * (n + 1)
for (i, l) in enumerate(__import__('sys').stdin.readlines()):
	(b, c) = map(int, l.split())
	a[i + 1] = (b, c)
r = [0] * n
r[0] = 1
for i in range(1, n):
	(p, q) = a[r[i - 1]]
	r[i] = p if q in a[p] else q
print(*r)


n = int(input())
d = []
for i in range(n):
	x = input().split()
	d.append([int(x[0]) - 1, int(x[1]) - 1])
first = d[0][0]
second = d[0][1]
if d[first][0] != second and d[first][1] != second:
	t = first
	first = second
	second = t
ans = [1, first + 1]
nex = second
while nex != 0:
	ans.append(nex + 1)
	if d[first][0] == second:
		nex = d[first][1]
	else:
		nex = d[first][0]
	first = second
	second = nex
for i in ans:
	print(i, end=' ')


def main():
	n = int(input())
	a = [[]] + [[int(x) for x in input().strip().split(' ')] for _ in range(n)]
	answer = solve(n, a)
	print(answer)

def solve(n, a):
	next_kid_of = [0 for _ in range(n + 1)]
	next_kid_set = set()
	for i in range(1, n + 1):
		if next_kid_of[i] > 0:
			continue
		(maybe_next_kid, other_kid) = a[i]
		if other_kid in a[maybe_next_kid] and maybe_next_kid not in next_kid_set:
			next_kid_of[i] = maybe_next_kid
			next_kid_of[maybe_next_kid] = other_kid
		else:
			next_kid_of[i] = other_kid
			next_kid_of[other_kid] = maybe_next_kid
		for kid in a[i]:
			next_kid_set.add(kid)
	next_kid = 1
	perm = [next_kid] + [0 for _ in range(n - 1)]
	for i in range(1, n):
		next_kid = next_kid_of[next_kid]
		perm[i] = next_kid
	return ' '.join((str(x) for x in perm))
main()


n = int(input())
m = [[0 for i in range(2)] for j in range(n)]
for k in range(n):
	(m[k][0], m[k][1]) = map(lambda x: int(x) - 1, input().split())
l = list()
l.append(0)
if m[0][0] in m[m[0][1]]:
	l.append(m[0][1])
	l.append(m[0][0])
else:
	l.append(m[0][0])
	l.append(m[0][1])
cpt = 2
while l[-1] != l[0]:
	if m[l[-2]][0] == l[-1]:
		l.append(m[l[-2]][1])
	else:
		l.append(m[l[-2]][0])
print(' '.join(map(lambda x: str(x + 1), l[:len(l) - 1])))


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))

def input():
	return stdin.readline().strip()

def fast():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in fast().split()]
(z, zz) = (fast, lambda : map(int, z().split()))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer, end='\n'):
	stdout.write(str(answer) + end)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
if randint(1, 200) == 177:
	print('hacked')
	exit()
n = int(z())
ans = [0] * (n + 1)
for _ in range(n):
	(x, y) = zzz()
	ans[_ + 1] = [x, y]
if n <= 3:
	print(*[i for i in range(1, n + 1)])
	exit()
new = [0] * n
new[0] = 1
for i in range(1, n):
	(l, r) = ans[new[i - 1]]
	new[i] = l if r in ans[l] else r
print(*new)


from sys import stdin
input = stdin.readline
n = int(input())
a = [[] for i in range(n + 1)]
for i in range(1, n + 1):
	a[i] = list(map(int, input().split()))
p = [0] * (n + 1)
p[1] = 1
(a1, a2) = a[1]
if a1 in a[a2]:
	p[2] = a2
	p[3] = a1
else:
	p[2] = a1
	p[3] = a2
for i in range(4, n + 1):
	p[i] = list(set(a[p[i - 2]]) & set(a[p[i - 1]]))[0]
print(*p[1:])


n = int(input())
if n == 3:
	print(3, 2, 1)
	exit()
d = []
d.append([0, 0])
for i in range(n):
	(x, y) = map(int, input().split())
	d.append([x, y])
x = 1
ans = []
ans.append(1)
while True:
	t = d[x][0]
	if d[t][0] == d[x][1] or d[t][1] == d[x][1]:
		ans.append(t)
		ans.append(d[x][1])
		x = d[x][1]
	else:
		ans.append(d[x][1])
		ans.append(t)
		x = t
	if len(ans) >= n:
		break
print(*ans[:n])


from collections import defaultdict

def fun():
	return 0
n = int(input())
tup = []
for i in range(n):
	(x, y) = [int(x) for x in input().split()]
	tup.append([x, y])
ans = []
for i in range(n):
	(x, y) = tup[i]
	f = False
	for j in range(2):
		if y == tup[x - 1][j]:
			f = True
	if f == False:
		(tup[i][0], tup[i][1]) = (y, x)
i = 0
d = defaultdict(fun)
while len(ans) < n:
	(x, y) = tup[i]
	if d[x] == 0 and d[y] == 0:
		d[x] += 1
		d[y] += 1
		ans.append(x)
		ans.append(y)
	elif d[x] == 0:
		d[x] += 1
		ans.append(x)
	else:
		d[y] += 1
		ans.append(y)
	i = y - 1
for i in ans:
	print(i, end=' ')


import sys
import bisect
from random import randint
input = lambda : sys.stdin.readline().strip('\r\n')
from math import gcd
sa = lambda : input()
sb = lambda : int(input())
sc = lambda : input().split()
sd = lambda : list(map(int, input().split()))
se = lambda : float(input())
sf = lambda : list(input())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7

def hnbhai():
	n = sb()
	g = [[] for i in range(n + 1)]
	for i in range(n):
		(a, b) = sd()
		g[i + 1] = [a, b]
	ans = [1]
	if n == 3:
		print(1, 2, 3)
		return
	i = 1
	j = 1
	while i < n:
		(a, b) = (g[j][0], g[j][1])
		if b in g[a]:
			ans.append(a)
			j = a
		else:
			ans.append(b)
			j = b
		i += 1
	print(*ans)
for _ in range(1):
	hnbhai()


import sys, math
from collections import defaultdict
n = int(input())
lines = sys.stdin.readlines()
lr = list()
dv = defaultdict(set)
for i in range(n):
	(a, b) = lines[i].strip().split(' ')
	dv[a].add(b)
	dv[b].add(a)
cur = '1'
res = [cur]
sv = {cur}
nex = lines[0].strip().split(' ')
l = list(dv['1'])
dv['1'] = set()
if nex[0] in l:
	dv['1'].add(nex[0])
else:
	dv['1'].add(nex[1])
while len(sv) < n:
	nex = dv[cur].pop()
	dv[nex].remove(cur)
	if len(dv[nex]) > 1:
		print(nex)
	cur = nex
	res.append(cur)
	sv.add(cur)
print(' '.join(res))


import sys
input = sys.stdin.readline

def calc(l):
	for _ in range(n - 3):
		(a1, a2) = a[l[-2] - 1]
		if a1 != l[-1] and a2 != l[-1]:
			break
		if a1 != l[-1]:
			l.append(a1)
		else:
			l.append(a2)
	if set([l[-1], l[0]]) == set(a[l[-2] - 1]) and set([l[0], l[1]]) == set(a[l[-1] - 1]):
		return l
	else:
		return [-1] * n
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
res = calc([1, a[0][0], a[0][1]])
if res != [-1] * n:
	print(*res)
	exit()
res = calc([1, a[0][1], a[0][0]])
print(*res)


n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
(x, y) = l[0]
if y in l[x - 1]:
	print(1, x, end=' ')
	n = x
	nn = y
else:
	print(1, y, end=' ')
	n = y
	nn = x
while nn != 1:
	(k, u) = l[n - 1]
	print(nn, end=' ')
	if k == nn:
		(n, nn) = (nn, u)
	else:
		(n, nn) = (nn, k)


n = int(input())
x = list()
for i in range(n):
	x.append(tuple(map(int, input().split())))
	x[i] = (x[i][0] - 1, x[i][1] - 1)
p = list()
p.append(0)
p.append(x[0][0])
p.append(x[0][1])
if x[0][0] in x[x[0][1]]:
	(p[1], p[2]) = (p[2], p[1])
for i in range(3, n):
	p.append(x[p[i - 2]][p[i - 1] == x[p[i - 2]][0]])
for i in range(n):
	print(p[i] + 1, end=' ')


n = int(input())
a = [(-1, -1)] + [tuple((int(j) for j in input().split())) for i in range(n)]
p = [1]
while len(p) < n:
	i = p[-1]
	if a[i][0] in a[a[i][1]]:
		p.append(a[i][1])
	else:
		p.append(a[i][0])
(i, j) = (p[-1], p[-2])
if a[i][0] in a[j]:
	p[0] = a[i][0]
else:
	p[0] = a[i][1]
print(' '.join((str(i) for i in p)))


n = int(input())
(d, mark) = ({}, {})
from sys import stdin
for i in range(n):
	(a1, a2) = map(int, stdin.readline().split())
	d[i] = [a1, a2]
	mark[i] = False
(a, b) = (d[0][0], d[0][1])
res = []
for i in range(n // 2):
	mark[a - 1] = True
	mark[b - 1] = True
	if d[a - 1][0] == b or d[a - 1][1] == b:
		res.append(a)
		res.append(b)
		(a, b) = (d[b - 1][0], d[b - 1][1])
	else:
		res.append(b)
		res.append(a)
		(a, b) = (d[a - 1][0], d[a - 1][1])
if mark[a - 1] == False:
	res.append(a)
if mark[b - 1] == False:
	res.append(b)
print(*res)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		n = ri()
		pos = {}
		z = []
		for i in range(n):
			(a, b) = ria()
			z.append([a, b])
			if a in pos:
				pos[a].append(i)
			else:
				pos[a] = [i]
			if b in pos:
				pos[b].append(i)
			else:
				pos[b] = [i]
		l = 0
		m = 0
		ans = [z[l][m]]
		now = z[l][m]
		used = {}
		for i in range(n - 1):
			for j in pos[now]:
				if j not in used:
					k = j
					break
			for j in z[k]:
				if j != now:
					now = j
					break
			used[k] = 1
			ans.append(now)
		if ans[-1] == 1:
			print(*ans)
		else:
			print(*ans[::-1])
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


n = int(input())
t = []
for i in range(n):
	t += [list(map(int, input().split()))]
	t[i][0] -= 1
	t[i][1] -= 1
k = 0

def f(a, b, c, d):
	if a == c or a == d or b == c or (b == d):
		return 1
	return 0
if n == 3:
	print(1, 2, 3)
	exit(0)
for i in range(n):
	print(k + 1, end=' ')
	if f(t[t[k][0]][0], t[t[k][0]][1], t[k][0], t[k][1]):
		k = t[k][0]
	else:
		k = t[k][1]


n = int(input())
dic = {}
for i in range(n):
	dic[i + 1] = list(map(int, input().strip().split()))
c = 1
ans = [c]
for i in range(n - 1):
	if dic[c][1] in dic[dic[c][0]]:
		c = dic[c][0]
	else:
		c = dic[c][1]
	ans.append(c)
if n == 3:
	print('1 2 3')
else:
	print(*ans)


from typing import *

def main():
	n = int(input())
	a = [tuple(map(int, input().split(' '))) for _ in range(n)]
	answer = solve(n, a)
	print(' '.join((str(x) for x in answer)))

def solve(n: int, a: List[Tuple[int, int]]) -> List[int]:
	ans = []
	already_appended = {}
	kid_in_question = 0
	while len(ans) < n:
		candidate_list = list(a[kid_in_question])
		chosen = candidate_list[0]
		for candidate in candidate_list:
			the_other = [x for x in candidate_list if x != candidate][0]
			if the_other in a[candidate - 1]:
				chosen = candidate
				break
		if chosen in already_appended:
			chosen = [x for x in candidate_list if x != chosen][0]
		ans.append(chosen)
		already_appended[chosen] = True
		kid_in_question = chosen - 1
	return ans
main()


t = int(input())
n = [[] for _ in range(t)]
order = []
for i in range(t):
	(a1, a2) = map(int, input().strip().split())
	order.append([a1, a2])
	n[a1 - 1].append(a2)
	n[a2 - 1].append(a1)
ans = []
flag = [0] * t
i = 0
while len(ans) < t:
	if n[i][0] not in order[0]:
		left = n[i][0]
		right = n[i][1]
	else:
		left = n[i][1]
		right = n[i][0]
	if not flag[left - 1]:
		ans.append(left)
		flag[left - 1] = 1
	if not flag[i]:
		ans.append(i + 1)
		flag[i] = 1
	if not flag[right - 1]:
		ans.append(right)
		flag[right - 1] = 1
	i = ans[-1] - 1
print(' '.join(map(str, ans)))


from bisect import bisect_left
n = int(input())
L = []
for a in range(n):
	L.append(list(map(int, input().split())))
i = 1
av = []
avv = set()
for a in range(n):
	av.append(i)
	avv.add(i)
	(p, q) = L[i - 1]
	i = q if p in L[q - 1] and q not in avv else p
print(' '.join(map(str, av)))


from sys import stdin, stdout
n = int(input())
d = {}
for i in range(1, n + 1):
	(x, y) = (int(r) for r in stdin.readline().split())
	d[i] = [x, y]
if n == 3:
	print(3, 2, 1)
else:
	ans = {}
	for i in range(1, n + 1):
		if d[i][0] in d[d[i][1]]:
			ans[i] = d[i][1]
		else:
			ans[i] = d[i][0]
	k = ans[1]
	for i in range(n):
		stdout.write(str(k) + ' ')
		k = ans[k]


n = int(input())
d = {}
sees = []
for _ in range(n):
	(a, b) = map(int, input().split())
	if a not in d:
		d[a] = set()
	if b not in d:
		d[b] = set()
	d[a].add(b)
	d[b].add(a)
	sees.append(set((a, b)))
res = []
if b in sees[a - 1]:
	res.extend([a, b])
	d[b].remove(a)
else:
	res.extend([b, a])
	d[a].remove(b)
for _ in range(n - 2):
	last = res[-1]
	nex = d[last].pop()
	d[nex].remove(last)
	res.append(nex)
for r in res:
	print(r, end=' ')
print()


n = int(input())
d = {}
for i in range(1, n + 1):
	d[i] = [*map(int, input().split())]
u = n - 1
c1 = 1
(a, b) = d[c1]
if b in d[a]:
	c2 = a
else:
	c2 = b
p = lambda x: print(x, end=' ')
p(c1)
while u > 0:
	p(c2)
	(c3,) = set(d[c1]).intersection(set(d[c2]))
	(c2, c1) = (c3, c2)
	u -= 1


from collections import defaultdict
n = int(input())
g = defaultdict(list)
for i in range(n):
	(a, b) = map(int, input().split())
	g[i + 1].append(a)
	g[i + 1].append(b)
ans = []
ans.append(1)
first = g[1][0]
second = g[1][1]
if g[first][0] == second or g[first][1] == second:
	ans.append(first)
	ans.append(second)
else:
	ans.append(second)
	ans.append(first)
pos = 1
for i in range(n - 3):
	if g[ans[pos]][0] != ans[pos + 1]:
		ans.append(g[ans[pos]][0])
	else:
		ans.append(g[ans[pos]][1])
	pos += 1
print(*ans)


def D():
	n = int(input())
	neighbours = [None]
	for i in range(n):
		neighbours.append([int(x) for x in input().split()])
	visited = set()
	ans = [None, 1]
	visited.add(1)
	(a, b) = (neighbours[1][0], neighbours[1][1])
	if b in neighbours[a]:
		ans += [a, b]
	else:
		ans += [b, a]
	visited.add(a)
	visited.add(b)
	for i in range(1, n):
		person = ans[i]
		if neighbours[person][0] not in visited:
			ans.append(neighbours[person][0])
			visited.add(neighbours[person][0])
		if neighbours[person][1] not in visited:
			ans.append(neighbours[person][1])
			visited.add(neighbours[person][1])
	ans = ans[1:]
	ans = [str(x) for x in ans]
	print(' '.join(ans))
D()


import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
n = iinp()
ml = [(0, 0)] + [tuple(mp()) for i in range(n)]
ansl = l1d(n)
ansl[0] = 1
j = 0
while j < n:
	(a, b) = ml[ansl[j]]
	if b in ml[a]:
		ansl[(j + 1) % n] = a
		ansl[(j + 2) % n] = b
	else:
		ansl[(j + 1) % n] = b
		ansl[(j + 2) % n] = a
	j += 2
outa(*ansl)


n = int(input())
data = [0] * n
for i in range(n):
	data[i] = [int(x) for x in input().split()]
if n == 3:
	print('1 2 3')
else:
	ret = []
	k = 0
	print(1, end='')
	for i in range(n - 1):
		(a, b) = (data[k][0], data[k][1])
		if a in data[b - 1]:
			print(' ' + str(b), end='')
			k = b - 1
		if b in data[a - 1]:
			print(' ' + str(a), end='')
			k = a - 1


n = int(input())
a = n * [0]
for i in range(n):
	a[i] = list(map(int, input().split()))
	a[i][0] -= 1
	a[i][1] -= 1
w = [0]
while 1:
	if len(w) >= n:
		if len(w) > n:
			w = w[:-1]
		s = ''
		for i in w:
			s += str(i + 1) + ' '
		print(s)
		break
	c = a[w[-1]][:]
	if c[0] in a[c[1]]:
		w += [c[1], c[0]]
	else:
		w += [c[0], c[1]]


n = int(input())
arr = [None] * n
for i in range(n):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	arr[i] = [a, b]
if n < 4:
	print(' '.join(list(map(str, range(1, n + 1)))))
	exit(0)
result = [None] * n
for (i, p) in enumerate(arr):
	if p[1] in arr[p[0]]:
		result[i] = p[0]
	else:
		result[i] = p[1]
idx = result[0]
while idx != 0:
	print(idx + 1, end=' ')
	idx = result[idx]
print(1)


n = int(input())
lst = [0] * n
for i in range(n):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	lst[i] = [a, b]
ans = [0] * n
cnt = 0
i = 0
temp1 = lst[0]
temp2 = lst[temp1[0]]
if temp2[0] == temp1[1] or temp2[1] == temp1[1]:
	ans[1] = temp1[0]
	ans[2] = temp1[1]
else:
	ans[1] = temp1[1]
	ans[2] = temp1[0]
for i in range(1, n - 2):
	temp = lst[ans[i]]
	if temp[0] == ans[i + 1]:
		ans[i + 2] = temp[1]
	else:
		ans[i + 2] = temp[0]
for i in ans:
	print(i + 1, end=' ')


n = int(input())
a = [None for _ in range(n + 1)]
for i in range(1, n + 1):
	a[i] = list(map(int, input().split()))
ret = a[1]
if ret[1] not in a[ret[0]]:
	ret = ret[::-1]
cur = 0
while cur < n - 2:
	(next1, next2) = a[ret[cur]]
	ret.append(ret[cur + 1] ^ next1 ^ next2)
	cur += 1
print(*ret)


def pr(total):
	print(' '.join([str(x) for x in total]))
	raise SystemExit()
d = {}
for _ in range(int(input())):
	d[_ + 1] = list(map(int, input().split()))
total = [1]
start = 1
if len(d) == 3:
	pr([1, 2, 3])
while True:
	i = total[-1]
	(zero, one) = d[i]
	if zero in d[one]:
		if one == start:
			pr(total)
		total.append(one)
		if zero == start:
			pr(total)
		total.append(zero)
	elif one in d[zero]:
		if zero == start:
			pr(total)
		total.append(zero)
		if one == start:
			pr(total)
		total.append(one)


from sys import stdin
input = stdin.readline
n = int(input())
dct = {}
for i in range(n):
	dct[i + 1] = set(map(int, input().split()))
narr = [1]
(x, y) = dct[1]
if y in dct[x]:
	narr.append(x)
	narr.append(y)
	nxt = x
else:
	narr.append(y)
	narr.append(x)
	nxt = y
while len(narr) < n:
	(x, y) = dct[nxt]
	if narr[-1] == x:
		narr.append(y)
		nxt = x
	else:
		narr.append(x)
		nxt = y
print(*narr)


import sys, math
n = int(sys.stdin.readline())
ans = []
a = []
for i in range(n):
	(x, y) = map(int, sys.stdin.readline().split())
	a.append([x, y])
s = set()
ans.append(1)
if a[a[0][0] - 1][0] == a[0][1] or a[a[0][0] - 1][1] == a[0][1]:
	ans.append(a[0][0])
	ans.append(a[0][1])
else:
	ans.append(a[0][1])
	ans.append(a[0][0])
s.add(1)
s.add(a[0][0])
s.add(a[0][1])
i = 1
while i < len(ans):
	if a[ans[i] - 1][0] not in s:
		ans.append(a[ans[i] - 1][0])
		s.add(a[ans[i] - 1][0])
	if a[ans[i] - 1][1] not in s:
		ans.append(a[ans[i] - 1][1])
		s.add(a[ans[i] - 1][1])
	i += 1
print(*ans)


input = __import__('sys').stdin.readline
from collections import deque as dq
lis = []
lis = dq(lis)
mat = []
n = int(input())
aa = [[] for i in range(n + 1)]
for i in range(n):
	(a, b) = map(int, input().split())
	mat.append([a, b])
	aa[a].append(b)
	aa[b].append(a)
st = []
lis.append(1)
lis.append(aa[1][1])
lis.appendleft(aa[1][0])
st.append(aa[1][1])
st.append(aa[1][0])
dd = 0
while len(st) != 0:
	dd += 1
	if dd == n:
		break
	a = st[0]
	st.pop(0)
	(b, c) = aa[a]
	if a == lis[0]:
		if b == lis[1]:
			lis.appendleft(c)
			st.append(c)
		else:
			lis.appendleft(b)
			st.append(b)
	elif b == lis[-2]:
		lis.append(c)
		st.append(c)
	else:
		lis.append(b)
		st.append(b)
if sorted([lis[1], lis[2]]) != sorted(mat[lis[0] - 1]):
	print(*list(lis)[:-2][::-1])
else:
	print(*list(lis)[:-2])


import sys
input = sys.stdin.buffer.readline

def main():
	n = int(input())
	XY = []
	S = set()
	for i in range(n):
		(x, y) = map(int, input().split())
		(x, y) = (x - 1, y - 1)
		XY.append((x, y))
		S.add((x, y))
		S.add((y, x))
	g = [[] for _ in range(n)]
	for i in range(n):
		(x, y) = XY[i]
		if (i, x) in S:
			g[i].append(x)
			g[x].append(y)
		else:
			g[i].append(y)
			g[y].append(x)
	s = []
	order = []
	visit = [-1] * n
	s.append(0)
	visit[0] = 0
	while s:
		v = s.pop()
		order.append(v)
		for u in g[v]:
			if visit[u] == -1:
				visit[u] = 0
				s.append(u)
	order = [x + 1 for x in order]
	print(*order)
main()


n = int(input())
x = []
for i in range(n):
	x.append(tuple(map(lambda x: int(x) - 1, input().split())))
if n == 3:
	if x[0][0] in x[x[0][1]]:
		print(x[0][1] % 3 + 1, (x[0][1] + 1) % 3 + 1, (x[0][1] + 2) % 3 + 1)
	else:
		print(x[0][0] % 3 + 1, (x[0][0] + 1) % 3 + 1, (x[0][0] + 2) % 3 + 1)
	exit()
c = [-1 for i in range(n)]
for i in range(n):
	if x[i][0] in x[x[i][1]]:
		c[i] = x[i][1]
	else:
		c[i] = x[i][0]
x = 0
i = 0
while i < n:
	print(x + 1, end=' ')
	x = c[x]
	i += 1


n = int(input())
memo = [[0] * 2 for i in range(n + 1)]
for i in range(1, n + 1):
	memo[i] = list(map(int, input().split()))
cur = 1
used = set()
for i in range(0, n):
	print(cur, end=' ')
	used.add(cur)
	if memo[cur][0] not in used and memo[cur][1] in memo[memo[cur][0]]:
		cur = memo[cur][0]
	else:
		cur = memo[cur][1]


n = int(input().rstrip())
adjList = []
for i in range(n):
	(u, v) = map(int, input().split())
	adjList.append([u, v])
point = 1
result = [point]
(nxt, nxtnxt) = adjList[0]
while len(result) < n:
	if nxtnxt not in adjList[nxt - 1]:
		(nxt, nxtnxt) = (nxtnxt, nxt)
	result.append(nxt)
	if nxtnxt == adjList[nxt - 1][0]:
		(nxt, nxtnxt) = (nxtnxt, adjList[nxt - 1][1])
	else:
		(nxt, nxtnxt) = (nxtnxt, adjList[nxt - 1][0])
print(*result)


from itertools import repeat
n = int(input())
a = [tuple((q - 1 for q in map(int, input().split()))) for _ in repeat(None, n)]
b = []
i = 0
while len(b) < len(a):
	b.append(i)
	if a[i][1] in a[a[i][0]]:
		b.append(a[i][0])
		i = a[i][1]
	else:
		b.append(a[i][1])
		i = a[i][0]
print(' '.join(map(str, (q + 1 for q in b[:len(a)]))))


n = int(input())
L = []
for i in range(n):
	L.append([])
for i in range(n):
	(x, y) = map(int, input().split())
	L[x - 1].append(y)
	L[y - 1].append(x)
	if i == 0:
		x2 = x
		y2 = y
OP = [1]
x = 0
predProsli = 0
prosli = 1
for i in range(n - 1):
	if predProsli == L[x][1]:
		OP.append(L[x][0])
		predProsli = prosli
		prosli = L[x][0]
		x = L[x][0] - 1
	else:
		OP.append(L[x][1])
		predProsli = prosli
		prosli = L[x][1]
		x = L[x][1] - 1
if OP[1] not in [x2, y2]:
	OP.reverse()
for i in range(len(OP)):
	print(OP[i], end=' ')


n = int(input())
deg = []
for i in range(n):
	a = list(map(int, input().split()))
	deg.append(a)
if n == 3:
	print(1, 2, 3)
	exit(0)
r = [0] * n
r[0] = 1
for i in range(1, n):
	(fi, se) = deg[r[i - 1] - 1]
	if se in deg[fi - 1]:
		r[i] = fi
	else:
		r[i] = se
print(*r)


n = int(input())
items = []
for i in range(n):
	(x, y) = map(int, input().split())
	items.append((x, y))

def search_and_sumbit(n, items):
	result = [1]
	result.extend(items[0])
	(length, j) = (3, 1)
	if length == n:
		return result
	else:
		x = items[result[j] - 1]
		if result[j + 1] in x:
			(j, length) = add(j, length, result, x)
		else:
			aux = result[j]
			result[j] = result[j + 1]
			result[j + 1] = aux
		while length < n:
			x = items[result[j] - 1]
			(j, length) = add(j, length, result, x)
	return result

def different_item(x, items):
	if items[0] == x:
		return items[1]
	return items[0]

def add(j, length, result, x):
	item = different_item(result[j + 1], x)
	result.append(item)
	j += 1
	length += 1
	return (j, length)
print(*search_and_sumbit(n, items))


def kk():
	n = int(input())
	if n == 3:
		return '1 2 3'
	kids = [[] for i in range(n + 1)]
	for i in range(1, n + 1):
		(a, b) = [int(i) for i in input().split()]
		kids[i].append(a)
		kids[i].append(b)
	res = '1'
	curr = 1
	init = 1
	while n > 0:
		k1 = kids[curr][0]
		k2 = kids[curr][1]
		next = k1 if kids[k1][0] == k2 or kids[k1][1] == k2 else k2
		if next != init:
			res += ' ' + str(next)
			curr = next
		n -= 1
	return res
print(kk())


n = int(input())
g = {i: set() for i in range(1, n + 1)}
d = {i: set() for i in range(1, n + 1)}
for i in range(1, n + 1):
	(x, y) = list(map(int, input().split()))
	g[x].add(y)
	g[y].add(x)
	d[i].add(x)
	d[i].add(y)
a = [1]
b = set(a)
i = 1
c = 0
while c < n:
	x = g[i]
	y = d[i]
	for j in y:
		if j in x and j not in b:
			a.append(j)
			b.add(j)
			i = j
			break
	c += 1
print(*a)


n = int(input())
arr = [0] + [tuple(map(int, input().split())) for _ in range(n)]
x = [[] for _ in range(n + 1)]
for i in range(1, n + 1):
	(a, b) = arr[i]
	x[a].append(b)
	x[b].append(a)
ans = [1]
start = 1
for _ in range(n):
	for t in x[start]:
		if t in arr[start]:
			ans.append(t)
			start = t
			break
print(*ans[:-1])


n = int(input())
ps = [[int(x) for x in input().split()] for _ in range(n)]
xs = [[] for _ in range(n)]
for (a, b) in ps:
	xs[a - 1].append(b - 1)
	xs[b - 1].append(a - 1)
res = [0]
res.append(xs[0][0])
for j in range(n - 2):
	(prev, cur) = (res[-2], res[-1])
	(na, nb) = xs[cur]
	res.append(na if nb == prev else nb)
for i in range(n):
	res[i] += 1
if res[1] not in ps[0]:
	res = res[::-1]
s = ' '.join(map(str, res))
print(s)


n = int(input().strip())
import collections
de = []
A = [0 for i in range(n + 5)]
for i in range(n):
	(x, y) = list(map(int, input().strip().split()))
	A[i + 1] = (x, y)
de.append(1)
de.append(A[1][0])
de.append(A[1][1])
while len(de) < n:
	a = de[-2]
	b = de[-1]
	x = A[a]
	y = A[b]
	if b in x:
		de.append(x[0] + x[1] - b)
	else:
		(de[-1], de[-2]) = (de[-2], de[-1])
print(' '.join(map(str, de)))


n = int(input())
arr = []
arr.append([0, 0])
for i in range(n):
	(x, y) = map(int, input().split())
	arr.append([x, y])
x = 1
ans = []
ans.append(1)
while 1:
	node = arr[x][0]
	if arr[node][0] == arr[x][1] or arr[node][1] == arr[x][1]:
		ans.append(node)
		ans.append(arr[x][1])
		x = arr[x][1]
	else:
		ans.append(arr[x][1])
		ans.append(node)
		x = node
	if len(ans) >= n:
		break
for i in range(n):
	print(ans[i], end=' ')
print()


d = dict()
n = int(input())
for i in range(n):
	(a, b) = [int(j) for j in input().split()]
	d[i] = {a - 1, b - 1}
ans = [0] * n
for i in range(n):
	(first, second) = list(d[ans[i]])
	if not d[ans[i]].isdisjoint(d[first]):
		ans[(i + 1) % n] = first
		ans[(i + 2) % n] = second
		continue
	if not d[ans[i]].isdisjoint(d[second]):
		ans[(i + 1) % n] = second
		ans[(i + 2) % n] = first
		continue
print(*[i + 1 for i in ans])


n = int(input())
d = {}
for i in range(1, n + 1):
	(x, y) = map(int, input().split())
	d[i] = [x, y]
l = []
l.append(1)
k = 1
t = 1
if n == 3:
	exit(print('1 2 3'))
while t != n:
	(x, y) = (d[k][0], d[k][1])
	if x in d[y]:
		l.append(y)
		t += 1
		k = y
	else:
		l.append(x)
		t += 1
		k = x
print(*l)


n = int(input())
data = [0] * n
for i in range(n):
	data[i] = [int(x) for x in input().split()]
visited = [True] * n
visited[0] = False
ret = []
k = 0
print(1, end='')
for i in range(n - 1):
	(a, b) = (data[k][0], data[k][1])
	if visited[b - 1] and a in data[b - 1]:
		visited[b - 1] = False
		print(' ' + str(b), end='')
		k = b - 1
	if visited[a - 1] and b in data[a - 1]:
		visited[a - 1] = False
		print(' ' + str(a), end='')
		k = a - 1


n = int(input())
p = [(None, None)]
for _ in range(n):
	p.append(list(map(int, input().split())))
if n == 3:
	print('1 2 3')
else:
	for (idx, (a, b)) in enumerate(p[1:], 1):
		if a in p[b]:
			p[idx] = [b]
		elif b in p[a]:
			p[idx] = [a]
	return_val = [p[1][0]]
	n -= 1
	while n:
		return_val.append(p[return_val[-1]][0])
		n -= 1
	print(' '.join([str(x) for x in return_val]))


n = int(input())
mas = []
itog = []
for i in range(n):
	a = list(map(int, input().split()))
	mas.append(a)
itog.append(1)
p = 0
while len(itog) < n - 1:
	if mas[p][1] in mas[mas[p][0] - 1]:
		itog.append(mas[p][0])
		p = mas[p][0] - 1
	else:
		itog.append(mas[p][1])
		p = mas[p][1] - 1
if mas[p][1] in mas[mas[p][0] - 1] and (not mas[p][0] in itog):
	itog.append(mas[p][0])
	p = mas[p][0] - 1
else:
	itog.append(mas[p][1])
	p = mas[p][1] - 1
for i in itog:
	print(i, end=' ')


def read_nums():
	return [int(x) for x in input().split()]

def main():
	(n,) = read_nums()
	d = {}
	for i in range(1, n + 1):
		d[i] = read_nums()
	circle = {1: d[1][0] if d[1][1] in d[d[1][0]] else d[1][1]}
	prev = 1
	cur = circle[1]
	while cur != 1:
		circle[cur] = list(set(d[prev]) & set(d[cur]))[0]
		prev = cur
		cur = circle[cur]
	nums = [1]
	cur = circle[1]
	while cur != 1:
		nums.append(cur)
		cur = circle[cur]
	print(' '.join([str(x) for x in nums]))

def __starting_point():
	main()
__starting_point()


n = int(input())
(d, ans) = ({}, [1 for i in range(n)])
for j in range(n):
	d[j + 1] = [int(i) for i in input().split(' ')]
for i in range(1, n):
	ans[i] = d[ans[i - 1]][1] if d[ans[i - 1]][0] in d[d[ans[i - 1]][1]] else d[ans[i - 1]][0]
print(*(ans if n > 3 else '1 2 3'))


def check(arr, a, b):
	next = -1
	l = a
	r = b
	ans = []
	for i in range(1, len(arr)):
		ans.append(l)
		if arr[l][0] == r:
			next = arr[l][1]
		elif arr[l][1] == r:
			next = arr[l][0]
		else:
			return 0
		l = r
		r = next
	for i in ans:
		print(i, end=' ')
	exit()

def main():
	n = int(input())
	arr = [[] for x in range(n + 1)]
	for i in range(1, n + 1):
		(x, y) = input().strip().split(' ')
		(x, y) = [int(x), int(y)]
		arr[i].append(x)
		arr[i].append(y)
	check(arr, 1, arr[1][0])
	check(arr, 1, arr[1][1])
main()


import math
import collections
import bisect
import heapq
import time
import itertools
import sys
N = int(input())
P = [[]]
for i in range(N):
	(a, b) = map(int, input().split())
	P.append([a, b])
nb = P[1]
ans = [1] + P[1]
if ans[2] not in P[ans[1]]:
	ans = [1] + [P[1][1], P[1][0]]
i = 1
while True:
	nb = [b for b in P[ans[i]] if b != ans[i + 1]][0]
	if nb == ans[0]:
		break
	ans.append(nb)
	i += 1
print(' '.join(map(str, ans)))


n = int(input())
input_items = []
for i in range(n):
	(i1, i2) = [int(item) for item in input().split()]
	input_items.append([i1 - 1, i2 - 1])
if n == 3:
	print('1 2 3')
	exit(0)
result = [1]
while len(result) != n:
	cur_item = result[-1] - 1
	candidates = input_items[cur_item]
	if candidates[0] in input_items[candidates[1]]:
		result.append(candidates[1] + 1)
	else:
		result.append(candidates[0] + 1)
print(*result)


n = int(input())
l = []
d = {}
for i in range(n + 1):
	d[i] = 0
l.append((0, 0))
for i in range(n):
	(a, b) = map(int, input().split())
	l.append((a, b))
if n == 3:
	print(1, 2, 3)
	exit(0)
for i in range(1, n + 1):
	if l[l[i][0]][0] == l[i][1] or l[l[i][0]][1] == l[i][1]:
		d[l[i][0]] = l[i][1]
	else:
		d[l[i][1]] = l[i][0]
c = 0
temp = 1
while c < n:
	print(d[temp], end=' ')
	temp = d[temp]
	c += 1


n = int(input())
a = [None]
for _ in range(n):
	ij = list(map(int, input().split(' ')))
	a.append(ij)
if n == 3:
	print('1 2 3')
	quit()
next_in = [0] * (n + 1)
for i in range(1, n + 1):
	[n_1, n_2] = a[i]
	if n_2 in a[n_1]:
		next_in[i] = n_1
	else:
		next_in[i] = n_2
ans = []
index = 1
for _ in range(n):
	ans.append(index)
	index = next_in[index]
print(' '.join(map(str, ans)))


from collections import defaultdict
from string import ascii_lowercase
from sys import stdin, stdout
input = stdin.readline

def main():
	n = int(input())
	after = [[] for _ in range(n + 1)]
	ind = [[] for _ in range(n + 1)]
	for i in range(1, n + 1):
		(c1, c2) = map(int, input().split())
		after[i].append(c1)
		after[i].append(c2)
		ind[c1].append(i)
		ind[c2].append(i)

	def check(a, b):
		left = n - 2
		last_a = a
		last_b = b
		res = [b, a]
		while left > 0:
			found = False
			for x in ind[last_a]:
				if last_b in after[x]:
					res.append(x)
					left -= 1
					(last_a, last_b) = (x, last_a)
					found = True
					break
			if not found:
				return False
		return list(reversed(res))
	ver = check(1, after[1][0])
	if ver:
		print(*ver)
	else:
		print(*check(1, after[1][1]))
main()


import sys

def Rd(f=int):
	return [f(x) for x in input().split()]

def Debug(x):
	print('\x1b[0;31m{}\x1b[0m'.format(x), file=sys.stderr)

def PrintFloats(arr):
	return ' '.join(('{:.10f}'.format(x) for x in arr))
n = int(input())
pairs = [Rd(int) for _ in range(n)]
ans = [1]
while len(ans) < n:
	cur = ans[-1]
	(u, v) = pairs[cur - 1]
	if u in pairs[v - 1]:
		ans += [v, u]
	else:
		ans += [u, v]
print(*ans[:n])


n = int(input())
a = {}
for i in range(1, n + 1):
	(n1, n2) = map(int, input().split())
	a[i] = (n1, n2)
if n == 3:
	print(1, 2, 3)
else:
	print(1, end=' ')
	next_ = 1
	for _ in range(n - 1):
		if a[next_][0] in a[a[next_][1]]:
			next_ = a[next_][1]
		else:
			next_ = a[next_][0]
		print(next_, end=' ')


n = int(input())
A = [-1]
ans = [1]
for i in range(n):
	A.append(tuple(map(int, input().split())))
a = A[1][0]
b = A[1][1]
c = A[a][0]
d = A[a][1]
if b == c or b == d:
	ans.append(a)
	ans.append(b)
else:
	ans.append(b)
	ans.append(a)
while len(ans) != n:
	p = A[ans[-2]]
	if p[0] == ans[-1]:
		ans.append(p[1])
	else:
		ans.append(p[0])
for i in ans:
	print(i, end=' ')


n = int(input())
l = []
(a, b) = (0, 0)
for i in range(n):
	s = list(map(int, input().split(' ')))
	a = int(s[0])
	b = int(s[1])
	l.append([a, b])
ans = [1]
(a, b) = (l[0][0], l[0][1])
if b in l[a - 1]:
	ans.append(a)
	ans.append(b)
	i = a
	j = b
else:
	ans.append(b)
	ans.append(a)
	i = b
	j = a
while len(ans) < n:
	for c in l[i - 1]:
		if c != j:
			ans.append(c)
			break
	i = j
	j = c
q = ''
q += str(ans[0])
for i in range(1, n):
	q += ' ' + str(ans[i])
print(q)


ans = []
n = int(input())
a = [[0, 0]]
for i in range(n):
	(x, y) = map(int, input().split())
	a.append([x, y])
ans.append(1)
l = 0
while l <= n + 2:
	if a[ans[-1]][1] in a[a[ans[-1]][0]]:
		ans.append(a[ans[-1]][0])
		ans.append(a[ans[-2]][1])
		l += 2
	else:
		ans.append(a[ans[-1]][1])
		ans.append(a[ans[-2]][0])
		l += 2
print(*ans[:n])


t = int(input())
a = []
for i in range(t):
	s = input().split(' ')
	a.append(s)
if t == 3:
	print(1, 2, 3)
else:
	count = 0
	i = 0
	res = []
	while count <= t:
		x = int(a[i][0])
		y = int(a[i][1])
		if int(a[x - 1][0]) == y or int(a[x - 1][1]) == y:
			count += 1
			res.append(x)
			i = x - 1
		else:
			count += 1
			res.append(y)
			i = y - 1
	for i in range(1, len(res)):
		print(res[i], end=' ')


n = int(input())
pairs = []
for _ in range(n):
	pairs.append(list(map(int, input().split())))
res = [1]
while len(res) < n:
	ind = res[-1]
	(first, second) = pairs[ind - 1]
	if first in pairs[second - 1]:
		res.append(second)
		res.append(first)
	else:
		res.append(first)
		res.append(second)
print(' '.join(map(str, res[:n])))


n = int(input())
a = [[] for i in range(n)]
for i in range(n):
	(a1, a2) = map(int, input().split())
	a[i].append(a1)
	a[i].append(a2)
if a[0][1] in a[a[0][0] - 1]:
	b = [1, a[0][0], a[0][1]]
else:
	b = [1, a[0][1], a[0][0]]
check = [0 for i in range(n + 1)]
check[1] = 1
check[a[0][0]] = 1
check[a[0][1]] = 1
i = a[0][0] - 1
while len(b) < n:
	if check[a[i][0]] == 0 and check[a[i][1]] == 0:
		if a[i][1] in a[a[i][0] - 1]:
			b.append(a[i][0])
			b.append(a[i][1])
			check[a[i][0]] = 1
			check[a[i][1]] = 1
			i = a[i][0] - 1
		else:
			b.append(a[i][1])
			b.append(a[i][0])
			check[a[i][0]] = 1
			check[a[i][1]] = 1
			i = a[i][1] - 1
	elif check[a[i][0]] == 0:
		b.append(a[i][0])
		check[a[i][0]] = 1
		i = a[i][0] - 1
	else:
		b.append(a[i][1])
		check[a[i][1]] = 1
		i = a[i][1] - 1
print(*b)


n = int(input())
dic1 = {}
for i in range(n):
	(a, b) = map(int, input().split())
	dic1[i + 1] = [a, b]
arr = [0] * (n + 1)
arr[1] = 1
i = 2
if n == 3:
	(arr[n - 1], arr[n]) = dic1[arr[n - 2]]
else:
	while i <= n:
		if dic1[arr[i - 1]][0] in dic1[dic1[arr[i - 1]][1]]:
			arr[i] = dic1[arr[i - 1]][1]
		else:
			arr[i] = dic1[arr[i - 1]][0]
		i += 1
print(*arr[1:])


n = int(input())
dict1 = {}
arr1 = [0] * (n + 1)
arr2 = [0] * (n + 1)
arr1[0] = 1
arr = []
temparr = []
for i in range(n):
	(x, y) = map(int, input().split())
	arr.append((x, y))
	if x == 1:
		temparr.append(y)
	elif y == 1:
		temparr.append(x)
if arr[0][0] == temparr[0]:
	arr1[1] = temparr[0]
	arr1[2] = arr[0][1]
elif arr[0][0] == temparr[1]:
	arr1[1] = temparr[1]
	arr1[2] = arr[0][1]
elif arr[0][1] == temparr[0]:
	arr1[1] = temparr[0]
	arr1[2] = arr[0][0]
elif arr[0][1] == temparr[1]:
	arr1[1] = temparr[1]
	arr1[2] = arr[0][0]
index = 1
for i in range(n - 3):
	if arr1[index + 1] == arr[arr1[index] - 1][0]:
		arr1[index + 2] = arr[arr1[index] - 1][1]
	else:
		arr1[index + 2] = arr[arr1[index] - 1][0]
	index += 1
print(*arr1[:n])


import math
n = int(input())
a = []
for i in range(n):
	(a1, a2) = map(int, input().split())
	a1 = a1 - 1
	a2 = a2 - 1
	a.append([a1, a2])
st = 0
b = [0] * n
for i in range(n):
	print(st + 1, end=' ')
	b[st] = 1
	a1 = a[st][0]
	a2 = a[st][1]
	if (a[a2][0] == a[st][0] or a[a2][1] == a[st][0]) and b[a2] == 0:
		st = a2
	elif (a[a1][0] == a[st][1] or a[a1][1] == a[st][1]) and b[a1] == 0:
		st = a1


t = 1
from heapq import heappop, heappush
for test in range(t):
	n = int(input())
	D = {}
	for i in range(1, n + 1):
		(a, b) = list(map(int, input().split()))
		D[i] = [a, b]
	if n == 3:
		ans = (1, 2, 3)
	else:
		ans = [1]
		(a, b) = D[1]
		if a in D[b]:
			ans.append(b)
			ans.append(a)
		else:
			ans.append(a)
			ans.append(b)
		while len(ans) < n:
			(a, b) = D[ans[-2]]
			if ans[-1] == a:
				ans.append(b)
			else:
				ans.append(a)
	print(*ans)


n = int(input())
d = {}
d1 = {}
for i in range(n):
	t = sorted(list(map(int, input().split())), reverse=True)
	d[i + 1] = t
l = []
i = 0
k = 1
if n == 3:
	print(1, 2, 3)
else:
	while i < n:
		z = d[k]
		s1 = d[z[0]]
		s2 = d[z[1]]
		l.append(k)
		if s1[0] == z[1] or s1[1] == z[1]:
			d1[k] = 1
			k = z[0]
		else:
			k = z[1]
		i += 1
	print(*l)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
d = []
for i in range(n):
	(a, b) = map(int, input().split())
	d.append([a, b])
(x, y) = (d[0][0], d[0][1])
if y in d[x - 1]:
	f = [1, x, y]
else:
	f = [1, y, x]
while len(f) < n:
	r = f[len(f) - 2]
	e = d[r - 1][0] + d[r - 1][1]
	f.append(e - f[len(f) - 1])
print(*f, sep=' ')


from collections import defaultdict
graph = defaultdict(list)
d = {}
n = int(input())
arr = []
for i in range(n):
	(u, v) = list(map(int, input().split()))
	graph[u].append(v)
	graph[v].append(u)
	d[i + 1] = [u, v]
ans = [0 for i in range(n)]
ans[0] = 1
cur = 1
for i in range(1, n):
	nei = d[cur]
	(x, y) = (nei[0], nei[1])
	if y in d[x]:
		ans[i] = x
		cur = x
	else:
		ans[i] = y
		cur = y
if n == 3:
	print(1, 2, 3)
else:
	print(*ans)


n = int(input())
l = [(0, 0)]
for i in range(n):
	(a, b) = map(int, input().split())
	l.append((a, b))
latest = 1
visited = [0] * (n + 1)
for i in range(n):
	visited[latest] = 1
	print(latest, end=' ')
	(x, y) = (l[latest][0], l[latest][1])
	if (l[x][0] == y or l[x][1] == y) and (not visited[x]):
		latest = x
	else:
		latest = y


n = int(input())
nextnode = [[] for i in range(n + 1)]
visited = [False] * (n + 1)
(fir, sec) = (-1, -1)
for i in range(n):
	(x, y) = map(int, input().split())
	nextnode[x].append(y)
	nextnode[y].append(x)
	if i == 0:
		(fir, sec) = (x, y)
		visited[fir] = True
		visited[sec] = True
ans = [fir, sec]
for i in range(n - 2):
	now = ans[-1]
	(p1, p2) = nextnode[now]
	if visited[p1] == True:
		ans.append(p2)
		visited[p2] = True
	else:
		ans.append(p1)
		visited[p1] = True
sindex = -1
for i in range(n):
	if ans[i] == 1:
		sindex = i
		break
(p, q) = (min(ans[(sindex + 1) % n], ans[(sindex + 2) % n]), max(ans[(sindex + 1) % n], ans[(sindex + 2) % n]))
(fir, sec) = (min(fir, sec), max(fir, sec))
if p == fir and q == sec:
	print(*ans)
else:
	print(*ans[::-1])


import sys
n = int(sys.stdin.readline().strip())
if n == 3:
	a = sys.stdin.readline()
	a = sys.stdin.readline()
	a = sys.stdin.readline()
	print('1 2 3')
else:
	kids1 = [0] * n
	kids2 = [0] * n
	for i in range(0, n):
		line = sys.stdin.readline().strip().split()
		kids1[i] = int(line[0]) - 1
		kids2[i] = int(line[1]) - 1
	answer = ['1'] + [0] * (n - 1)
	j1 = 0
	if kids1[0] == kids1[kids2[0]] or kids1[0] == kids2[kids2[0]]:
		answer[1] = str(kids2[0] + 1)
		j2 = kids2[0]
	else:
		answer[1] = str(kids1[0] + 1)
		j2 = kids1[0]
	for i in range(0, n - 2):
		if kids1[j1] == j2:
			temp = j1
			j1 = j2
			j2 = kids2[temp]
		else:
			temp = j1
			j1 = j2
			j2 = kids1[temp]
		answer[i + 2] = str(j2 + 1)
	print(' '.join(answer))


n = int(input())
a = {}
for i in range(1, n + 1):
	(x, y) = map(int, input().split())
	a[i] = (x, y)
ans = [1]
next1 = 1
for _ in range(n - 1):
	if a[next1][0] in a[a[next1][1]]:
		next1 = a[next1][1]
		ans.append(next1)
	else:
		next1 = a[next1][0]
		ans.append(next1)
if n == 3:
	print(1, 2, 3)
else:
	print(*ans)


n = int(input())
queue = [1]
edge = [[] for i in [0] * n]
for i in range(n):
	(a, b) = map(int, input().split())
	edge[a - 1].append(b)
	edge[b - 1].append(a)
clockwise = [n, a, b]
l = 2
queue.append(edge[0][0])
while l < n:
	queue.append(sum(edge[queue[-1] - 1]) - queue[-2])
	l += 1
if queue[(queue.index(n) + 1) % n] != a and queue[(queue.index(n) + 1) % n] != b:
	queue.reverse()
print(' '.join([str(i) for i in queue]))


n = int(input())
d = {}
for i in range(n):
	d[i + 1] = tuple(map(int, input().split()))
p = [1]
to_resolve = 1
for i in range(n - 1):
	candidates = d[to_resolve]
	if candidates[1] in d[candidates[0]]:
		to_resolve = candidates[0]
	else:
		to_resolve = candidates[1]
	p.append(to_resolve)
if n == 3:
	print('1 2 3')
else:
	print(' '.join(map(str, p)))


def next(n):
	b = a[n - 1][1]
	c = a[n - 1][2]
	if b in a[c - 1][1:]:
		return c
	else:
		return b
n = int(input())
a = []
for _ in range(n):
	(a1, a2) = map(int, input().split())
	a.append([_ + 1, a1, a2])
ans = [1]
for i in range(n - 1):
	ans.append(next(ans[-1]))
if n == 3:
	print(1, 2, 3)
else:
	print(*ans)


n = int(input())
a = [list(map(lambda x: x - 1, map(int, input().split()))) for i in range(n)]
start = 0
flag = False
ans = []
should_be = -1
while True:
	if start == 0 and flag == True:
		break
	ans.append(start + 1)
	flag = True
	next = a[start][0]
	ok = should_be == -1 or should_be == next
	if ok and (a[start][1] == a[next][0] or a[start][1] == a[next][1]):
		if should_be > -1:
			assert next == should_be
		should_be = a[start][1]
		start = next
		continue
	next = a[start][1]
	ok = should_be == -1 or should_be == next
	if ok and (a[start][0] == a[next][0] or a[start][0] == a[next][1]):
		if should_be > -1:
			assert next == should_be
		should_be = a[start][0]
		start = next
		continue
	assert False
for x in ans:
	print(x, end=' ')


t = int(input())
inp_arr = []
inp_arr.append([])
temp = t
while temp > 0:
	inp = list(map(int, input().split()))
	inp_arr.append(inp)
	temp -= 1
temp = 0
last = 1
last_neigh = 0
while temp < t:
	o1 = inp_arr[last][0]
	o2 = inp_arr[last][1]
	if temp == 0:
		if o1 == inp_arr[o2][0] or o1 == inp_arr[o2][1]:
			print(1, o2, o1, end=' ')
			last = o2
			last_neigh = o1
		else:
			print(1, o1, o2, end=' ')
			last = o1
			last_neigh = o2
		temp += 3
	else:
		if o1 == last_neigh:
			print(o2, end=' ')
			last = last_neigh
			last_neigh = o2
		else:
			print(o1, end=' ')
			last = last_neigh
			last_neigh = o1
		temp += 1
print()


n = int(input())
v = {}
for i in range(1, n + 1):
	v[i] = set(map(int, input().split()))
ans = []
ans_s = set()
ans.append(1)
ans_s.add(1)
while len(ans) < n:
	for i in v[ans[-1]]:
		if len(v[i].intersection(v[ans[-1]])) > 0 and i not in ans_s:
			ans.append(i)
			ans_s.add(i)
			break
print(' '.join(map(str, ans)))


def read(type=1):
	if type:
		file = open('input.dat', 'r')
		n = int(file.readline())
		a = []
		for i in range(n):
			a.append(list(map(int, file.readline().split())))
		file.close()
	else:
		n = int(input().strip())
		a = []
		for i in range(n):
			a.append(list(map(int, input().strip().split())))
	return (n, a)

def solve():
	sol = [1]
	used = [0 for i in range(n)]
	while len(sol) < n - 1:
		last = sol[-1] - 1
		used[last] = 1
		if a[last][0] in a[a[last][1] - 1]:
			sol.append(a[last][1])
			used[a[last][1] - 1] = 1
			sol.append(a[last][0])
		else:
			sol.append(a[last][0])
			used[a[last][0] - 1] = 1
			sol.append(a[last][1])
	used[sol[-1] - 1] = 1
	if len(sol) != n:
		for i in range(n):
			if used[i] == 0:
				sol.append(i + 1)
	return sol

def write(sol):
	line = ''
	for v in sol:
		line += str(v) + ' '
	print(line)
(n, a) = read(0)
sol = solve()
write(sol)


n = int(input())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append((a, b))
ll = []
i = 0
cou = 0
while cou < n:
	(a, b) = (l[i][0], l[i][1])
	if l[a - 1][0] == b or l[a - 1][1] == b:
		ll.append(a)
		ll.append(b)
		i = b - 1
		cou += 2
	else:
		ll.append(b)
		ll.append(a)
		i = a - 1
		cou += 2
if n == 3:
	print(1, 2, 3)
elif n % 2 != 0:
	for i in range(cou - 1):
		print(ll[i], end=' ')
else:
	for i in range(cou):
		print(ll[i], end=' ')


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	arr = []
	n = int(input())
	for _ in range(n):
		arr.append(read())
	ans = [0] * n
	ans[0] = 1
	sett = set()
	sett.add(1)
	for i in range(n - 1):
		(x, y) = arr[ans[i] - 1]
		if x in sett:
			ans[(i + 1) % n] = y
			continue
		if y in arr[x - 1]:
			ans[(i + 1) % n] = x
			sett.add(x)
		else:
			ans[(i + 1) % n] = y
			sett.add(y)
	print(*ans)
solve()


n = int(input())
if n == 3:
	ans = [1, 2, 3]
else:
	a = [None] + [list(map(int, input().split())) for _ in range(n)]
	ans = []
	i = 1
	while True:
		ans.append(i)
		j = a[i][0]
		if a[i][1] not in a[j]:
			j = a[i][1]
		i = j
		if i == 1:
			break
print(*ans)


n = int(input())
e = n
dic = {}
dety = []
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	if a in dic:
		dic[a].append(b)
	else:
		dic[a] = [b]
	if b in dic:
		dic[b].append(a)
	else:
		dic[b] = [a]
	dety.append((a, b))
tot = []
item = 1
prev = 0
while n > 0:
	if prev == dic[item][0]:
		prev = item
		tot.append(dic[item][1])
		item = dic[item][1]
	else:
		prev = item
		tot.append(dic[item][0])
		item = dic[item][0]
	n -= 1
if tot.index(1) != e - 1:
	if tot[tot.count(1) + 1] != dety[0][0] and tot[tot.count(1) + 1] != dety[0][1]:
		tot.reverse()
elif tot[tot.index(2) + 1] != dety[1][0] and tot[tot.index(2) + 1] != dety[1][1]:
	tot.reverse()
total = ''
for item in tot:
	total += str(item) + ' '
print(total[:-1])


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heapreplace, heappushpop

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
test_case = 1
while test_case:
	test_case -= 1
	n = ii()
	if n == 3:
		print(1, 2, 3)
		exit()
	a = [0]
	for _ in range(n):
		a.append(li())
	ans = [1]
	(y, x) = a[1]
	if y not in a[x]:
		(x, y) = (y, x)
	ans.append(x)
	ans.append(y)
	for i in range(1, n - 2):
		(x, y) = a[ans[i]]
		if x == ans[-1]:
			x = y
		ans.append(x)
	print(*ans)


n = int(input())
sosed = dict()
for c in range(n):
	sosed[c + 1] = set()
(z1, z2) = map(int, input().split())
sosed[z1].add(z2)
sosed[z2].add(z1)
i = [z1, z2]
for __ in range(1, n):
	(z1, z2) = map(int, input().split())
	sosed[z1].add(z2)
	sosed[z2].add(z1)
	if z1 == 1 or z2 == 1:
		if max(z1, z2) in i:
			i = [max(z1, z2)]
pred = set()
cnt = 0
i = i[0]
print(1, end=' ')
pred.add(1)
while cnt < n - 1:
	cnt += 1
	print(i, end=' ')
	pred.add(i)
	for y in sosed[i]:
		if y not in pred:
			i = y


n = int(input())
a = [[0, 0]]
ans = [1]
for i in range(n):
	a.append([int(x) for x in input().split()])
options = a[1]
ans.append(options[0])
ans.append(options[1])
if ans[-1] not in a[ans[-2]]:
	(ans[1], ans[2]) = (ans[2], ans[1])
for i in range(1, n - 1):
	options = a[ans[i]]
	idx = options.index(ans[-1])
	rem = options[1 - idx]
	ans.append(rem)
print(*ans[:-1])


N = int(input())
a = [[]]
for i in range(N):
	a.append([int(i) for i in input().split()])
ans = [1]
ind = 1
(m, n) = a[1]
done = [0] * (N + 1)
done[1] = 1
if m in a[n]:
	ans.append(n)
	done[n] = 1
else:
	ans.append(m)
	done[m] = 1
while len(ans) != N:
	(m, n) = a[ans[-2]]
	if done[m] == 1:
		ans.append(n)
		done[n] = 1
	else:
		ans.append(m)
		done[m] = 1
for i in ans:
	print(i, end=' ')