Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the League of Leesins World Championship comes to an end! 

The tournament consisted of $n$ ($n \ge 5$) teams around the world. Before the tournament starts, Bob has made a prediction of the rankings of each team, from $1$-st to $n$-th. After the final, he compared the prediction with the actual result and found out that the $i$-th team according to his prediction ended up at the $p_i$-th position ($1 \le p_i \le n$, all $p_i$ are unique). In other words, $p$ is a permutation of $1, 2, \dots, n$.

As Bob's favorite League player is the famous "3ga", he decided to write down every $3$ consecutive elements of the permutation $p$. Formally, Bob created an array $q$ of $n-2$ triples, where $q_i = (p_i, p_{i+1}, p_{i+2})$ for each $1 \le i \le n-2$. Bob was very proud of his array, so he showed it to his friend Alice.

After learning of Bob's array, Alice declared that she could retrieve the permutation $p$ even if Bob rearranges the elements of $q$ and the elements within each triple. Of course, Bob did not believe in such magic, so he did just the same as above to see Alice's respond.

For example, if $n = 5$ and $p = [1, 4, 2, 3, 5]$, then the original array $q$ will be $[(1, 4, 2), (4, 2, 3), (2, 3, 5)]$. Bob can then rearrange the numbers within each triple and the positions of the triples to get $[(4, 3, 2), (2, 3, 5), (4, 1, 2)]$. Note that $[(1, 4, 2), (4, 2, 2), (3, 3, 5)]$ is not a valid rearrangement of $q$, as Bob is not allowed to swap numbers belong to different triples.

As Alice's friend, you know for sure that Alice was just trying to show off, so you decided to save her some face by giving her any permutation $p$ that is consistent with the array $q$ she was given. 


-----Input-----

The first line contains a single integer $n$ ($5 \le n \le 10^5$) — the size of permutation $p$.

The $i$-th of the next $n-2$ lines contains $3$ integers $q_{i, 1}$, $q_{i, 2}$, $q_{i, 3}$ ($1 \le q_{i, j} \le n$) — the elements of the $i$-th triple of the rearranged (shuffled) array $q_i$, in random order. Remember, that the numbers within each triple can be rearranged and also the positions of the triples can be rearranged.

It is guaranteed that there is at least one permutation $p$ that is consistent with the input. 


-----Output-----

Print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \le p_i \le n$) such that $p$ is consistent with array $q$. 

If there are multiple answers, print any. 


-----Example-----
Input
5
4 3 2
2 3 5
4 1 2

Output
1 4 2 3 5

Difficulty: MEDIUM_HARD

Solutions:
n = int(input())
l = []
d = {}
for i in range(n):
	d[i + 1] = []
for i in range(n - 2):
	l.append(list(map(int, input().split())))
	d[l[-1][0]].append(i)
	d[l[-1][1]].append(i)
	d[l[-1][2]].append(i)
t = 0
for i in range(n):
	if len(d[i + 1]) == 1:
		t = i + 1
		break
ans = [t]
a = t
for i in l[d[t][0]]:
	if len(d[i]) == 2:
		b = i
	elif len(d[i]) == 3:
		c = i
ans.append(b)
ans.append(c)
count = 0
while count < n - 3:
	for i in d[b]:
		if i not in d[a] and i in d[c]:
			t = i
	for i in l[t]:
		if i != b and i != c:
			ans.append(i)
			(a, b, c) = (b, c, i)
			break
	count += 1
print(*ans)


def answer(n, q):
	p = []
	dic = {}
	for i in range(1, n + 1):
		dic[i] = []
	for li in q:
		dic[li[0]].append(li)
		dic[li[1]].append(li)
		dic[li[2]].append(li)
	one = []
	two = []
	for i in range(1, n + 1):
		if len(dic[i]) == 1:
			one.append(i)
		elif len(dic[i]) == 2:
			two.append(i)
	a = one[0]
	b = 0
	c = 0
	for i in two:
		for li in dic[i]:
			if a in li:
				b = i
				c = sum(li) - (a + b)
				break
	p = p + [a, b, c]
	for _ in range(n - 3):
		for li in dic[b]:
			if (a in li) is False and (b in li and c in li):
				a = b
				b = c
				c = sum(li) - (a + b)
				p.append(c)
	return ' '.join([str(c) for c in p])
n = int(input())
col = n - 2
q = []
for _ in range(col):
	li = list(map(int, input().split()))
	q.append(li)
print(answer(n, q))


import sys
input = sys.stdin.readline
n = int(input())
adj_list = [[] for _ in range(n)]
for _ in range(n - 2):
	(q1, q2, q3) = map(int, input().split())
	adj_list[q1 - 1].append(q2 - 1)
	adj_list[q1 - 1].append(q3 - 1)
	adj_list[q2 - 1].append(q3 - 1)
	adj_list[q2 - 1].append(q1 - 1)
	adj_list[q3 - 1].append(q1 - 1)
	adj_list[q3 - 1].append(q2 - 1)
for i in range(n):
	adj_list[i] = list(set(adj_list[i]))
for i in range(n):
	if len(adj_list[i]) == 2:
		start = i
		break
ans = [start]
n1 = adj_list[start][0]
n2 = adj_list[start][1]
if len(adj_list[n1]) == 3:
	ans.append(n1)
else:
	ans.append(n2)
for i in range(2, n):
	n1 = ans[i - 2]
	n2 = ans[i - 1]
	s1 = set(adj_list[n1])
	s2 = set(adj_list[n2])
	s3 = s1 & s2
	if i >= 3:
		s3.remove(ans[i - 3])
	ans.append(list(s3)[0])
ans2 = [ai + 1 for ai in ans]
print(*ans2)


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def main():
	n = int(input())
	a = [sorted(map(int, input().split())) for _ in range(n - 2)]
	b = defaultdict(list)
	f = [0] * (n + 1)
	for (j, i) in enumerate(a):
		for k in i:
			f[k] += 1
		b[i[0], i[1]].append(j)
		b[i[1], i[2]].append(j)
		b[i[0], i[2]].append(j)
	for i in range(1, n + 1):
		if f[i] == 1:
			x = i
			break
	for i in range(n - 2):
		if x in a[i]:
			ind = i
			break
	ans = [0] * n
	a[ind].remove(x)
	(ans[0], ans[1], ans[2]) = (x, min(a[ind][0], a[ind][1]), max(a[ind][0], a[ind][1]))
	v = [0] * (n - 2)
	v[ind] = 1
	i = 3
	while i < n:
		y = b[min(ans[i - 2], ans[i - 1]), max(ans[i - 1], ans[i - 2])]
		if not v[y[0]]:
			a[y[0]].remove(ans[i - 2])
			a[y[0]].remove(ans[i - 1])
			ans[i] = a[y[0]].pop()
			v[y[0]] = 1
		elif len(y) > 1 and (not v[y[1]]):
			a[y[1]].remove(ans[i - 2])
			a[y[1]].remove(ans[i - 1])
			ans[i] = a[y[1]].pop()
			v[y[1]] = 1
		elif len(y) > 2 and (not v[y[2]]):
			a[y[2]].remove(ans[i - 2])
			a[y[2]].remove(ans[i - 1])
			ans[i] = a[y[2]].pop()
			v[y[2]] = 1
		else:
			(ans[i - 2], ans[i - 3]) = (ans[i - 3], ans[i - 2])
			i -= 1
		i += 1
	print(*ans)
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')
main()


n = int(input())
t = [set() for x in range(n + 1)]
w = []
for x in range(0, n - 2):
	(a, b, c) = map(int, input().split())
	t[a].add(b)
	t[a].add(c)
	t[b].add(a)
	t[b].add(c)
	t[c].add(a)
	t[c].add(b)
for x in range(1, n + 1):
	if len(t[x]) == 2:
		w.append(x)
		break
for x in range(0, len(t)):
	if w[0] in t[x]:
		if len(t[x]) == 3 and len(w) == 1:
			w.append(x)
		t[x].remove(w[0])
for x in range(1, n - 1):
	curr = t[w[x - 1]].intersection(t[w[x]])
	ww = list(curr)
	w.append(ww[-1])
	t[w[x + 1]].remove(w[x])
print(' '.join((str(x) for x in w)))


n = int(input())
ar = []
for i in range(n - 2):
	ar.append(list(map(int, input().split())))
br = [False] * n
vr = [0] * n
rel = dict()
ans = []
for i in range(n):
	rel[i + 1] = set()
for i in range(n - 2):
	a = ar[i][0]
	b = ar[i][1]
	c = ar[i][2]
	rel[a].add(b)
	rel[a].add(c)
	rel[b].add(a)
	rel[b].add(c)
	rel[c].add(a)
	rel[c].add(b)
for i in range(n):
	if len(rel[i + 1]) == 2:
		start = i + 1
		break
br[start - 1] = True
ans.append(start)
for i in rel[start]:
	if len(rel[i]) == 3:
		ans.append(i)
		br[i - 1] = True
	else:
		x = i
ans.append(x)
br[x - 1] = True
i = 1
while i < n - 2:
	for j in rel[ans[i]]:
		if br[j - 1] == False:
			ans.append(j)
			br[j - 1] = True
			break
	i += 1
for i in range(n):
	print(ans[i], end=' ')
print()


import sys
input = sys.stdin.readline
N = int(input())
Arrays = [list(map(int, input().split())) for _ in range(N - 2)]
dic = {}
for A in Arrays:
	A.sort()
	for a in A:
		if a in dic:
			dic[a].append(A)
		else:
			dic[a] = [A]
for n in range(1, N + 1):
	if len(dic[n]) == 1:
		start = n
		break
for m in dic[n][0]:
	if len(dic[m]) == 2:
		second = m
	elif len(dic[m]) == 3:
		third = m
ans = [start, second, third]
num = third
for _ in range(N - 3):
	now = set(ans[-3:])
	for A in dic[num]:
		T = []
		for a in A:
			if not a in now:
				T.append(a)
		if len(T) == 1:
			next_num = T[0]
			break
	ans.append(next_num)
	num = next_num
print(*ans)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd

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()
n = ii()
a = [set() for _ in range(n + 1)]
for _ in range(n - 2):
	(x, y, z) = mi()
	a[x].add(y)
	a[x].add(z)
	a[y].add(x)
	a[y].add(z)
	a[z].add(y)
	a[z].add(x)
p = []
for i in range(1, n + 1):
	if len(a[i]) == 2:
		p.append(i)
		break
for x in a[p[0]]:
	if len(a[x]) == 3:
		p.append(x)
		a[x].remove(p[0])
		break
for i in range(1, n - 1):
	x = a[p[i]] & a[p[i - 1]]
	z = [v for v in x]
	p.append(z[0])
	a[p[i + 1]].remove(p[i])
print(*p)


n = int(input())
q = []
ans = []
b = [[] for i in range(n + 1)]
for i in range(n - 2):
	q.append(list(map(int, input().split())))
	for j in q[i]:
		b[j].append(i)
for i in range(n):
	if len(b[i]) == 1:
		break
ans.append(i)
for x in range(n - 1):
	for j in b[i]:
		for k in q[j]:
			if len(ans) == 1 and ans[0] in q[j] and (len(b[k]) == 2) or (len(ans) > 1 and k not in ans[-3:] and (ans[-2] in q[j]) and (ans[-1] in q[j])):
				ans.append(k)
				i = k
for i in range(len(ans)):
	print(ans[i], end=' ')


n = int(input())
n1 = n - 2
d = {}
d1 = {}
visit = {}
l1 = []
for i in range(1, n + 1):
	d[i] = []
	d1[i] = 0
	visit[i] = False
while n1:
	n1 -= 1
	(a, b, c) = map(int, input().split())
	d[a].append(b)
	d[a].append(c)
	d1[a] += 1
	d[b].append(a)
	d[b].append(c)
	d1[b] += 1
	d[c].append(b)
	d[c].append(a)
	d1[c] += 1
d1 = dict(sorted(d1.items(), key=lambda x: x[1]))
for i in d1:
	if not visit[i]:
		visit[i] = True
		l1.append(i)
	x = sorted(d[i], key=lambda x: d1[x])
	for j in x:
		if not visit[j]:
			visit[j] = True
			l1.append(j)
			x += d[j]
print(*l1)


def main():
	n = int(input())
	arr = []
	indexes = [[] for _ in range(n + 1)]
	for i in range(n - 2):
		abc = readIntArr()
		for z in abc:
			indexes[z].append(i)
		arr.append(abc)
	for first in range(1, n + 1):
		if len(indexes[first]) == 1:
			break
	firstGroup = indexes[first][0]
	for second in arr[firstGroup]:
		if len(indexes[second]) == 2:
			break
	ans = [first, second]
	group = firstGroup
	visitedGroups = [False for _ in range(n - 2)]
	while True:
		visitedGroups[group] = True
		for third in arr[group]:
			if third != first and third != second:
				break
		ans.append(third)
		stillHaveGroup = False
		for nextGroup in indexes[second]:
			if visitedGroups[nextGroup] == False:
				stillHaveGroup = True
				break
		if stillHaveGroup == False:
			break
		group = nextGroup
		first = second
		second = third
	oneLineArrayPrint(ans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]
inf = float('inf')
MOD = 10 ** 9 + 7
main()


rinp = [4, 6, 2, 1, 7, 3, 5]
n = int(input())
ans = list()
BIN = list(((i, list()) for i in range(n)))
i = 2
while i < n:
	inp = list((int(x) - 1 for x in input().split()))
	for ch in inp:
		BIN[ch][1].append(inp)
	i += 1
SB = sorted(BIN, key=lambda x: len(x[1]))
now = SB[0][0]
last = None
while True:
	ans.append(now)
	nowl = BIN[now][1]
	lnowl = len(nowl)
	if lnowl == 3:
		for item in nowl:
			try:
				item.remove(now)
			except:
				pass
			try:
				item.remove(last)
			except:
				pass
			if len(item) == 1:
				next = item[0]
				break
	elif lnowl == 2:
		for item in nowl:
			try:
				item.remove(now)
			except:
				pass
			try:
				item.remove(last)
			except:
				pass
			if len(item) == 1:
				next = item[0]
				break
	else:
		tl = nowl[0]
		tl.remove(now)
		if not tl:
			break
		for next in tl:
			ttl = BIN[next][1]
			if len(ttl) == 2:
				break
	(now, last) = (next, now)
print(' '.join((str(x + 1) for x in ans)))


n = int(input())
d = {}
lis = []
cnt = [0] * (n + 1)
pos = [[] for i in range(n + 1)]
ar = [list(map(int, input().split())) for _ in range(n - 2)]
for i in range(n - 2):
	(a, b, c) = ar[i]
	pos[a].append(i)
	pos[b].append(i)
	pos[c].append(i)
	cnt[a] += 1
	cnt[b] += 1
	cnt[c] += 1
ans = []
for i in range(n + 1):
	if cnt[i] == 1:
		ans.append(i)
		break
(a, b, c) = ar[pos[ans[0]][0]]
if cnt[a] == 2:
	ans.append(a)
elif cnt[b] == 2:
	ans.append(b)
elif cnt[c] == 2:
	ans.append(c)
if cnt[a] == 3:
	ans.append(a)
elif cnt[b] == 3:
	ans.append(b)
elif cnt[c] == 3:
	ans.append(c)
for i in range(n - 3):
	for j in pos[ans[-2]]:
		(a, b, c) = ar[j]
		if ans[-1] in ar[j] and ans[-3] not in ar[j]:
			t = [a, b, c]
			t.remove(ans[-1])
			t.remove(ans[-2])
			ans.append(t[0])
			break
print(*ans)


n = int(input())
triplets = []
pos = {i: [] for i in range(1, n + 1)}
for i in range(n - 2):
	a = list(map(int, input().split()))
	triplets.append(a)
	for k in a:
		pos[k].append(i)
freq = {i: 0 for i in range(1, n + 1)}
freq_1 = set()
for trip in triplets:
	for i in range(3):
		freq[trip[i]] += 1
		if freq[trip[i]] == 1:
			freq_1.add(trip[i])
		if freq[trip[i]] > 1 and trip[i] in freq_1:
			freq_1.remove(trip[i])
x = list(freq_1)[0]
ans = []
ans.append(x)
x_in_triplet = None
for trip in triplets:
	if x in trip:
		x_in_triplet = trip
		break
elements_to_check = [i for i in x_in_triplet if i != x and freq[i] == 2]
ans.append(elements_to_check[0])
done = set()
done.add(ans[-1])
done.add(ans[-2])
for i in range(2, n - 1):
	temp_freq = {}
	for k in pos[ans[-1]]:
		for j in triplets[k]:
			if j in done:
				continue
			if j not in temp_freq:
				temp_freq[j] = 0
			temp_freq[j] += 1
	for x in temp_freq:
		if temp_freq[x] == 2:
			ans.append(x)
			done.add(x)
			break
ans.append(list(freq_1)[1])
print(*ans)


n = int(input())
q = []
qh = {}
qc = {}
for i in range(n):
	qh[i] = []
	qc[i] = 0
for i in range(n - 2):
	(q1, q2, q3) = map(int, input().split())
	q.append([q1 - 1, q2 - 1, q3 - 1])
	for d in [q1, q2, q3]:
		qh[d - 1].append(i)
		qc[d - 1] += 1
pp = []
for i in range(n):
	if qc[i] == 1:
		pp.append(i)
(p1, p2) = pp
p3 = -1
p4 = -1
for i in q[qh[p2][0]]:
	if qc[i] == 3:
		p3 = i
	if qc[i] == 2:
		p4 = i
(p5, p6) = (-1, -1)
for i in q[qh[p1][0]]:
	if qc[i] == 3:
		p5 = i
	if qc[i] == 2:
		p6 = i
	qc[i] -= 1
p = [p1, p6, p5]
d = qh[p6][0]
if d == qh[p1][0]:
	d = qh[p6][1]
for i in q[d]:
	qc[i] -= 1
for i in range(n - 6):
	fg = p[-1]
	d = -1
	for j in qh[fg]:
		if j not in qh[p[-2]]:
			d = j
	for j in q[d]:
		if qc[j] == 2:
			p.append(j)
		qc[j] -= 1
if n != 5:
	p.append(p3)
p.append(p4)
p.append(p2)
print(' '.join(map(lambda x: str(x + 1), p)))


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

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

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

def i():
	return input()
n = ii()
a = []
for i in range(n + 1):
	a.append(set())
for i in range(n - 2):
	(x, y, z) = mp()
	a[x].add(y)
	a[x].add(z)
	a[y].add(x)
	a[y].add(z)
	a[z].add(y)
	a[z].add(x)
ans = []
for i in range(n):
	if len(a[i]) == 2:
		ans.append(i)
		break
for i in a[ans[0]]:
	if len(a[i]) == 3:
		ans.append(i)
		a[i].remove(ans[0])
		break
for i in range(1, n - 1):
	x = a[ans[i]] & a[ans[i - 1]]
	ans.append(x.pop())
	a[ans[i + 1]].remove(ans[i])
print(*ans)


import sys

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

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
n = oint()
a = []
m = dict()
for i in range(n - 2):
	q = list(rint())
	a.append(q)
	for j in range(3):
		if q[j] in m:
			m[q[j]] = m[q[j]] + [i]
		else:
			m[q[j]] = [i]
start = []
second = []
for j in range(1, n + 1):
	if len(m[j]) == 1:
		start.append(j)
	if len(m[j]) == 2:
		second.append(j)
s = start[0]
if m[s][0] in m[second[0]]:
	sec = second[0]
else:
	sec = second[1]
ans = [s, sec]
for i in range(2, n):
	qi = set(m[ans[i - 2]]).intersection(set(m[ans[i - 1]]))
	if len(qi) == 1:
		next = set(a[qi.pop()]).difference(set([ans[i - 2], ans[i - 1]])).pop()
	else:
		next1 = set(a[qi.pop()]).difference(set([ans[i - 2], ans[i - 1]])).pop()
		next2 = set(a[qi.pop()]).difference(set([ans[i - 2], ans[i - 1]])).pop()
		if next1 == ans[-3]:
			next = next2
		else:
			next = next1
	ans.append(next)
print(*ans)


n = int(input())
d = dict()
c = [0] * (n + 1)
w = [0] * (n + 1)
for i in range(n - 2):
	a = sorted(map(int, input().split()))
	for j in a:
		c[j] += 1
		w[j] = a
	for (x, y) in ((0, 1), (0, 2), (1, 2)):
		z = (a[x], a[y])
		if z in d:
			d[z].append(a[3 - x - y])
		else:
			d[z] = [a[3 - x - y]]
for s in range(1, n + 1):
	if c[s] == 1:
		break
for e in range(s + 1, n + 1):
	if c[e] == 1:
		break
q = w[s]
a = []
for i in range(n, 5, -1):
	a.append(s)
	k = 0
	for j in q:
		c[j] -= 1
		if c[j] == 1:
			k = j
	w = q.copy()
	w.remove(s)
	for j in d[tuple(w)]:
		if j != s:
			break
	w.append(j)
	w.sort()
	q = w
	s = k
if n >= 5:
	a.append(s)
	for m in q:
		if c[m] == 3:
			break
	z = sum(q) - s - m
	a.append(z)
	a.append(m)
	for i in d[tuple(sorted((z, m)))]:
		if i != s:
			break
	a.append(i)
	a.append(e)
print(*a)


n = int(input())
a = [[[0 for i in range(2)] for i in range(3)] for i in range(n)]
count = [0 for i in range(100000)]
r = [0 for i in range(n)]
for i in range(n - 2):
	(x, y, z) = tuple(map(int, input().split()))
	a[x - 1][count[x - 1]][0] = y
	a[x - 1][count[x - 1]][1] = z
	a[y - 1][count[y - 1]][0] = x
	a[y - 1][count[y - 1]][1] = z
	a[z - 1][count[z - 1]][0] = x
	a[z - 1][count[z - 1]][1] = y
	count[x - 1] += 1
	count[y - 1] += 1
	count[z - 1] += 1
for i in range(n):
	if count[i] == 1:
		r[0] = i + 1
		break
x = a[r[0] - 1][0][0]
y = a[r[0] - 1][0][1]
if count[x - 1] == 2:
	r[1] = x
	r[2] = y
else:
	r[1] = y
	r[2] = x
for i in range(3, n):
	for j in range(3):
		if a[r[i - 1] - 1][j][0] == r[i - 2] and a[r[i - 1] - 1][j][1] != r[i - 3]:
			r[i] = a[r[i - 1] - 1][j][1]
			break
		if a[r[i - 1] - 1][j][1] == r[i - 2] and a[r[i - 1] - 1][j][0] != r[i - 3]:
			r[i] = a[r[i - 1] - 1][j][0]
			break
print(*r)


from collections import defaultdict
n = int(input())
graph = [[] for i in range(n + 1)]
for _ in range(n - 2):
	a = list(map(int, input().split()))
	graph[a[0]] += [a[1], a[2]]
	graph[a[1]] += [a[0], a[2]]
	graph[a[2]] += [a[1], a[0]]
for i in range(1, n + 1):
	graph[i] = list(set(graph[i]))
visited = [False for i in range(n + 1)]
ans = []
for i in range(1, n + 1):
	if len(graph[i]) == 2:
		ans.append(i)
		visited[i] = True
		break
for j in graph[i]:
	if len(graph[j]) == 3:
		ans.append(j)
		visited[j] = True
		break
for i in range(n - 2):
	for j in graph[ans[i]]:
		if not visited[j]:
			ans.append(j)
			visited[j] = True
for i in ans:
	print(i, end=' ')


import math
import sys
from collections import defaultdict, Counter
from functools import lru_cache
n = int(input())
q = []
arr = []
Dict = defaultdict(list)
for _ in range(n - 2):
	(a, b, c) = [int(i) for i in input().split()]
	arr.append(a)
	arr.append(b)
	arr.append(c)
	q.append([a, b, c])
count = Counter(arr)
val = -1
for i in range(1, n + 1):
	if count[i] == 1:
		val = i
		break
for i in range(len(q)):
	Dict[q[i][0]].append(i)
	Dict[q[i][1]].append(i)
	Dict[q[i][2]].append(i)
ans = []
temp = q[Dict[val][0]]
first = [0] * 3
cur_ind = Dict[val][0]
for i in range(3):
	first[count[temp[i]] - 1] = temp[i]
ans = []
ans += first
while len(set(Dict[ans[-1]]).intersection(set(Dict[ans[-2]]))) > 1:
	a1 = list(set(Dict[ans[-1]]).intersection(set(Dict[ans[-2]])))
	for i in a1:
		if i != cur_ind:
			temp = q[i]
			ind = i
	cur = -1
	for i in range(3):
		if temp[i] != ans[-2] and temp[i] != ans[-1]:
			cur = temp[i]
			break
	ans += [cur]
	cur_ind = ind
print(*ans)


n = int(input())
legit = []
count = [set() for i in range(n + 1)]
for i in range(n - 2):
	val = [int(x) for x in input().split(' ')]
	count[val[0]].add(val[1])
	count[val[0]].add(val[2])
	count[val[1]].add(val[0])
	count[val[1]].add(val[2])
	count[val[2]].add(val[1])
	count[val[2]].add(val[0])
end = []
for i in range(n + 1):
	if len(count[i]) == 2:
		end.append(i)
start = end[0]
visited = set()
output = [start]
prev = None
while start != end[1]:
	visited.add(start)
	for i in iter(count[start]):
		if prev == None:
			if len(count[i]) == 3:
				prev = start
				start = i
				output.append(start)
				break
		elif i not in visited and start in count[i] and (i in count[prev]):
			prev = start
			start = i
			output.append(start)
			break
print(*output)


n = int(input())
p = [[] for i in range(n + 1)]
cnt = [0 for i in range(n + 1)]
for i in range(n - 2):
	(a, b, c) = list(map(int, input().split()))
	cnt[a] += 1
	cnt[b] += 1
	cnt[c] += 1
	p[a].append(b)
	p[a].append(c)
	p[b].append(a)
	p[b].append(c)
	p[c].append(a)
	p[c].append(b)
first = None
for i in range(1, n + 1):
	if cnt[i] == 1:
		first = i
		break
ans = [-1 for i in range(n)]
ans[0] = first
second = None
third = None
for u in p[first]:
	if cnt[u] == 2:
		second = u
	if cnt[u] == 3:
		third = u
ans[1] = second
ans[2] = third
vis = [False for i in range(n + 1)]
vis[first] = 1
vis[second] = 1
vis[third] = 1
for i in range(3, n):
	nc = ans[i - 3]
	for u in p[ans[i - 2]]:
		if u != nc and u != ans[i - 1] and (not vis[u]):
			ans[i] = u
			vis[u] = 1
			break
for a in ans:
	print(a, end=' ')


n = int(input())
mas = []
cou = []
for i in range(n + 1):
	mas.append([])
	cou.append(0)
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	mas[a].append([a, b, c])
	mas[b].append([a, b, c])
	mas[c].append([a, b, c])
	cou[a] += 1
	cou[b] += 1
	cou[c] += 1
for i in range(1, n + 1):
	if cou[i] == 1:
		x = i
		break
y = -1
for i in range(1, n + 1):
	if cou[i] == 2:
		if y == -1:
			y = i
		else:
			z = i
if not y in mas[x][0]:
	y = z
for i in mas[x][0]:
	if i != x and i != y:
		z = i
		break
ans = [x, y, z]
for k in range(3, n):
	x = ans[k - 3]
	y = ans[k - 2]
	z = ans[k - 1]
	for i in mas[y]:
		if y in i and z in i and (not x in i):
			for j in range(len(i)):
				if i[j] != y and i[j] != z:
					h = i[j]
					break
	ans.append(h)
print(*ans)


n = int(input())
triple = list()
fre = dict()
for i in range(1, n + 1):
	fre[i] = 0
for j in range(n - 2):
	c = list(map(int, input().split()))
	c.sort()
	triple.append(c)
	fre[c[0]] += 1
	fre[c[1]] += 1
	fre[c[2]] += 1
fre_num = list()
for i in range(1, n + 1):
	fre_num.append([fre[i], i])
all_duplet = dict()
for i in triple:
	a1 = min(i[0], i[1])
	a2 = max(i[0], i[1])
	if (a1, a2) in all_duplet:
		all_duplet[a1, a2].append(i[2])
	else:
		all_duplet[a1, a2] = list()
		all_duplet[a1, a2].append(i[2])
	a1 = min(i[2], i[1])
	a2 = max(i[2], i[1])
	if (a1, a2) in all_duplet:
		all_duplet[a1, a2].append(i[0])
	else:
		all_duplet[a1, a2] = list()
		all_duplet[a1, a2].append(i[0])
	a1 = min(i[0], i[2])
	a2 = max(i[0], i[2])
	if (a1, a2) in all_duplet:
		all_duplet[a1, a2].append(i[1])
	else:
		all_duplet[a1, a2] = list()
		all_duplet[a1, a2].append(i[1])
ans = list()
ans_set = set()
fre_num.sort()
ans.append(fre_num[0][1])
for i in range(len(triple)):
	if ans[-1] in triple[i]:
		first_triple = triple[i]
		first_triple.remove(ans[-1])
		break
if fre[first_triple[0]] < fre[first_triple[1]]:
	ans.append(first_triple[0])
	ans.append(first_triple[1])
else:
	ans.append(first_triple[1])
	ans.append(first_triple[0])
for i in ans:
	ans_set.add(i)
while len(ans) < n:
	a1 = min(ans[-1], ans[-2])
	a2 = max(ans[-1], ans[-2])
	for j in all_duplet[a1, a2]:
		if j not in ans_set:
			ans_set.add(j)
			ans.append(j)
			break
print(*ans)


n = int(input())
memo = [[] for i in range(n + 1)]
Q = []
for i in range(n - 2):
	Q.append([int(s) for s in input().split()])
for i in range(n - 2):
	q = Q[i]
	memo[q[0]].append(i)
	memo[q[1]].append(i)
	memo[q[2]].append(i)
start = 0
for i in range(1, n + 1):
	if len(memo[i]) == 1:
		start = i
		break
p = []
p.append(start)
qIndex = memo[start][0]
for poss in Q[qIndex]:
	if len(memo[poss]) == 2:
		p.append(poss)
for poss in Q[qIndex]:
	if len(memo[poss]) == 3:
		p.append(poss)
for i in range(n - 3):
	a = p[i]
	b = p[i + 1]
	c = p[i + 2]
	for i in memo[b]:
		if i in memo[c] and i not in memo[a]:
			index2 = i
			break
	for poss in Q[index2]:
		if poss != b and poss != c:
			p.append(poss)
print(' '.join((str(i) for i in p)))


import os
import sys

def solve(triplets):
	if len(triplets) == 1:
		return triplets[0]
	n = len(triplets) + 2
	x = [[] for _ in range(n + 1)]
	counts = [0 for _ in range(n + 1)]
	for trip in triplets:
		next_triplet = tuple(sorted(trip))
		for t in trip:
			x[t].append(next_triplet)
			counts[t] += 1
	(root, last) = [idx for (idx, c) in enumerate(counts) if c == 1]
	ans = [root]
	seen = {x[root][0]}
	current = x[root][0]
	while len(ans) < n:
		cands = [i for i in current if i != root]
		if last in current:
			ans.append([k for k in cands if k != last][0])
			ans.append(last)
			break
		for c in cands:
			next_triplet = [t for t in x[c] if t not in seen]
			if len(next_triplet) == 1 and (len(x[c]) == 3 or len(ans) == 1):
				next_triplet = next_triplet[0]
				break
		else:
			raise Exception(ans, cands)
		ans.append(c)
		seen.add(next_triplet)
		root = c
		current = next_triplet
	return ans
solve([[1, 2, 5], [1, 3, 5], [4, 3, 5]])

def pp(input):
	n = int(input())
	triplets = [tuple(map(int, input().split())) for _ in range(n - 2)]
	print(' '.join(map(str, solve(triplets))))
if 'paalto' in os.getcwd():
	from string_source import string_source
	pp(string_source('5\n4 3 2\n2 3 5\n4 1 2\n'))
	pp(string_source('5\n    4 5 3\n    2 5 1\n    1 3 5'))
	pp(string_source('4\n1 2 3\n2 3 4\n'))
	pp(string_source('3\n2 3 4\n'))
else:
	pp(sys.stdin.readline)


n = int(input())
triples = []
start = 0
start_val = 0
freq_idx = [0 for x in range(n + 1)]
triples = [0 for x in range(n - 2)]
for i in range(n - 2):
	triple = [int(x) for x in input().strip().split(' ')]
	triples[i] = triple
	for j in triple:
		if type(freq_idx[j]) != list:
			freq_idx[j] = list()
		freq_idx[j].append(i)
start = -1
end = -1
for i in range(1, n + 1):
	if len(freq_idx[i]) == 1:
		if start == -1:
			start = i
		else:
			end = i
			break
print(start, end=' ')
done = {freq_idx[start][0]}
last_triple = triples[freq_idx[start][0]]
cnt = 1
while cnt != n - 3:
	for t in last_triple:
		to_check = set(freq_idx[t]) - done
		if len(to_check) == 1:
			idx = next(iter(to_check))
			print(t, end=' ')
			last_triple = triples[idx]
			done.add(idx)
			cnt += 1
			break
end_triple = sorted(triples[freq_idx[end][0]], key=lambda x: len(freq_idx[x]), reverse=True)
print(' '.join([str(x) for x in end_triple]))


n = int(input())
q = []
b = []
r = []
for i in range(n + 1):
	b.append([])
for i in range(n - 2):
	q.append(list(map(int, input().split())))
	b[q[i][0]].append(i)
	b[q[i][1]].append(i)
	b[q[i][2]].append(i)
for i in range(1, n + 1):
	if len(b[i]) == 1:
		r.append(i)
		break
for _ in range(n - 1):
	for e in b[i]:
		for k in q[e]:
			if len(r) == 1 and k not in r and (len(b[k]) == 2) or (len(r) > 1 and k not in r[-3:] and (r[-2] in q[e]) and (r[-1] in q[e])):
				r.append(k)
				i = k
print(*r)


import sys
import collections
import heapq
import math
input = sys.stdin.readline

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

def rstr():
	return input().strip()

def rint():
	return int(input().strip())

def rintas():
	return [int(i) for i in input().strip().split()]

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
n = rint() + 1
q = []
indexes = [[] for _ in range(n)]
counts = [0] * n
for i in range(n - 2 - 1):
	q.append(rintas())
	for j in q[-1]:
		indexes[j].append(i)
		counts[j] += 1
tmp = counts[:]
cur = counts.index(1)
nxt = indexes[cur][0]
seen = set()
ans = []
while True:
	for i in indexes[cur]:
		if i in seen:
			continue
		nxt = i
		seen.add(i)
	(a, b, c) = q[nxt]
	if counts[a] == counts[b] == counts[c] == 1:
		break
	ans.append(cur)
	counts[a] -= 1
	counts[b] -= 1
	counts[c] -= 1
	if counts[a] == 1:
		cur = a
	elif counts[b] == 1:
		cur = b
	elif counts[c] == 1:
		cur = c
for i in q[nxt]:
	if tmp[i] == 3:
		ans.append(i)
for i in q[nxt]:
	if tmp[i] == 2:
		ans.append(i)
for i in q[nxt]:
	if tmp[i] == 1:
		ans.append(i)
print(' '.join(map(str, ans)))


from collections import defaultdict
n = int(input())
A = []
for i in range(n - 2):
	A.append(list(map(int, input().split())))
count = {i + 1: 0 for i in range(n)}
third = {}
for (a, b, c) in A:
	if (a, b) not in third:
		third[a, b] = []
	third[a, b].append(c)
	if (b, a) not in third:
		third[b, a] = []
	third[b, a].append(c)
	if (a, c) not in third:
		third[a, c] = []
	third[a, c].append(b)
	if (c, a) not in third:
		third[c, a] = []
	third[c, a].append(b)
	if (b, c) not in third:
		third[b, c] = []
	third[b, c].append(a)
	if (c, b) not in third:
		third[c, b] = []
	third[c, b].append(a)
	count[a] += 1
	count[b] += 1
	count[c] += 1
first = 0
for i in range(n):
	if count[i + 1] == 1:
		first = i + 1
		break
second = 0
for i in range(n):
	if count[i + 1] == 2:
		second = i + 1
		if (first, second) in third:
			break
		else:
			second = 0
ans = [first, second]
aset = set()
aset.add(first)
aset.add(second)
for i in range(n - 2):
	for val in third[first, second]:
		if val not in aset:
			ans.append(val)
			aset.add(val)
			(first, second) = (second, val)
			break
print(*ans)


import sys
from collections import defaultdict
n = int(input())
count = [0] * (n + 1)
d = defaultdict(list)
di = 10 ** 6
for (q1, q2, q3) in (list(map(int, l.split())) for l in sys.stdin):
	count[q1] += 1
	count[q2] += 1
	count[q3] += 1
	d[q1 * di + q2 if q1 < q2 else q2 * di + q1].append(q3)
	d[q1 * di + q3 if q1 < q3 else q3 * di + q1].append(q2)
	d[q2 * di + q3 if q2 < q3 else q3 * di + q2].append(q1)
(i1, i2) = ([], [])
for i in range(1, n + 1):
	if count[i] == 1:
		i1.append(i)
	elif count[i] == 2:
		i2.append(i)
key = []
ans = [0] * n
if (i1[0] * di + i2[0] if i1[0] < i2[0] else i2[0] * di + i1[0]) in d:
	key = [i1[0], i2[0]]
else:
	key = [i1[0], i2[1]]
(ans[0], ans[1]) = (key[0], key[1])
used = {key[0], key[1]}
for i in range(2, n):
	next_key = key[0] * di + key[1] if key[0] < key[1] else key[1] * di + key[0]
	next_l = d[next_key]
	next_n = next_l[0] if next_l[0] not in used else next_l[1]
	ans[i] = next_n
	(key[0], key[1]) = (key[1], next_n)
	used.add(next_n)
print(*ans)


from collections import defaultdict
n = int(input())
arc = [0] * (n + 1)
dic = defaultdict(lambda : [])
for _ in range(n - 2):
	(a, b, c) = map(int, input().split())
	arc[a] += 1
	arc[b] += 1
	arc[c] += 1
	dic[a].append((b, c))
	dic[c].append((b, a))
	dic[b].append((a, c))
p1 = arc.index(1)
arc[p1] = 0
arc2 = arc.copy()
final = arc.index(1)
ans = [p1]
pres = dic[p1][0]
dic2 = defaultdict(lambda : 0)
dic2[final] = 1
dic2[p1] = 1
for i in range(n - 4):
	if arc[pres[0]] < arc[pres[1]]:
		temp = pres[0]
		temp1 = pres[1]
	else:
		temp = pres[1]
		temp1 = pres[0]
	for el in dic[temp]:
		if temp1 in el and dic2[el[0]] == 0 and (dic2[el[1]] == 0):
			pres = el
			break
	arc[temp] -= 1
	arc[temp1] -= 1
	dic2[temp] -= 1
	ans.append(temp)
if arc2[pres[0]] > arc2[pres[1]]:
	temp = pres
else:
	temp = pres[::-1]
ans.extend(temp)
ans.append(final)
print(*ans)


def solve():
	n = int(input())
	q = [list(map(int, input().split())) for i in range(n - 2)]
	ind = [[] for i in range(n + 1)]
	count = [0] * (n + 1)
	for i in range(n - 2):
		for j in q[i]:
			ind[j].append(i)
			count[j] += 1
	for i in range(1, n + 1):
		if len(ind[i]) == 1:
			start = i
			break
	for i in range(start + 1, n + 1):
		if len(ind[i]) == 1:
			end = i
			break
	ans = []
	ans.append(start)
	used = [0] * n
	used2 = [0] * (n + 1)
	used2[start] = 1
	prev = [*q[ind[start][0]]]
	while len(ans) != n - 1:
		prd = []
		for i in ind[start]:
			if used[i]:
				continue
			used[i] = 1
			for j in q[i]:
				count[j] -= 1
				prd.append(j)
		for i in prd:
			if count[i] < 2 and i in prev and (not used2[i]):
				ans.append(i)
				used2[i] = 1
				start = i
				prev = prd
				break
	ans.append(end)
	print(*ans)
solve()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

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

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

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

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(1):
	n = l()[0]
	A = [l() for i in range(n - 2)]
	d = {}
	for i in range(n - 2):
		for k in A[i]:
			if k not in d:
				d[k] = []
			d[k].append(A[i])
	for i in range(n):
		if len(d[i + 1]) == 1:
			start = i + 1
			break
	for i in range(n):
		if len(d[i + 1]) == 2 and (start in d[i + 1][0] or start in d[i + 1][1]):
			mid = i + 1
	ans = [start, mid]
	for x in d[start][0]:
		if x not in ans:
			ans.append(x)
			break
	curr = x
	for i in range(n - 3):
		for ele in d[curr]:
			if ans[-1] in ele and ans[-2] in ele and (ans[-3] not in ele):
				ans.append(sum(ele) - ans[-1] - ans[-2])
				curr = ans[-1]
				break
	print(*ans)


def next(arr):
	a = []
	s = set(arr)
	for i in s:
		x = arr.count(i)
		if x == 2:
			a.append(x)
	return (a[0], a[1])
n = int(input())
a = [[] for i in range(n + 1)]
for i in range(n - 2):
	x = list(map(int, input().split()))
	for j in x:
		a[j].append(x)
f = -1
l = -1
for i in range(1, n + 1):
	if len(a[i]) == 1 and f == -1:
		f = i
	elif len(a[i]) == 1:
		l = i
		break
f2 = -1
for i in range(3):
	if len(a[a[f][0][i]]) == 2:
		f2 = a[f][0][i]
l2 = -1
for i in range(3):
	if len(a[a[l][0][i]]) == 2:
		l2 = a[l][0][i]
ans = [f, f2]
curr = f2
pc = f
vis = [0] * (n + 1)
vis[f] = 1
vis[f2] = 1
for i in range(n - 2):
	x = a[curr]
	for j in range(len(x)):
		if curr in x[j] and pc in x[j]:
			if x[j][0] != curr and x[j][0] != pc:
				t = x[j][0]
				if vis[t] == 0:
					ans.append(t)
					pc = curr
					curr = t
					vis[t] = 1
			if x[j][1] != curr and x[j][1] != pc:
				t = x[j][1]
				if vis[t] == 0:
					ans.append(t)
					pc = curr
					curr = t
					vis[t] = 1
			if x[j][2] != curr and x[j][2] != pc:
				t = x[j][2]
				if vis[t] == 0:
					ans.append(t)
					pc = curr
					curr = t
					vis[t] = 1
print(*ans)


import sys
input = sys.stdin.readline
n = int(input())
q = [list(map(int, input().split())) for i in range(n - 2)]
s = [set() for i in range(n + 1)]
for i in range(n - 2):
	(a, b, c) = q[i]
	s[a].add(b)
	s[a].add(c)
	s[b].add(a)
	s[b].add(c)
	s[c].add(a)
	s[c].add(b)
p = []
for i in range(1, n + 1):
	if len(s[i]) == 2:
		p.append(i)
		break
for i in range(n + 1):
	if p[0] in s[i]:
		if len(s[i]) == 3 and len(p) == 1:
			p.append(i)
		s[i].remove(p[0])
for i in range(1, n - 1):
	cur = s[p[i - 1]].intersection(s[p[i]])
	p.append(list(cur)[-1])
	s[p[i + 1]].remove(p[i])
print(*p)


import sys, math, collections
import sys, io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
N = int(input())
A = []
for i in range(N - 2):
	A.append(list(map(int, input().split())))
DC = collections.defaultdict(int)
DI = collections.defaultdict(list)
for i in A:
	for j in i:
		DC[j] += 1
		DI[j].append(i)
for i in range(1, N + 1):
	if DC[i] == 1:
		F = i
		break
ANS = [F]
for i in DI[F][0]:
	if DC[i] == 2:
		V = i
		ANS.append(V)
		break
cnt = 0
PV = -1
U = {F, V}
while True:
	for i in DI[V]:
		if i[0] in U and i[1] in U and (i[2] in U):
			continue
		elif F in i:
			T = i
			break
	for i in T:
		if i != F and i != V:
			ANS.append(i)
			F = V
			V = i
			U.add(V)
			U.add(F)
			break
	cnt += 1
	if cnt >= N - 2:
		break
print(*ANS)


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')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

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

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def toord(c):
	return ord(c) - ord('a')
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	n = N()
	rec = [0] * (n + 1)
	gp = [[] for _ in range(n + 1)]
	for _ in range(n - 2):
		(a, b, c) = RL()
		rec[a] += 1
		rec[b] += 1
		rec[c] += 1
		gp[a].append(b)
		gp[a].append(c)
		gp[b].append(a)
		gp[b].append(c)
		gp[c].append(a)
		gp[c].append(b)
	crec = rec.copy()
	q = []
	for i in range(1, n + 1):
		if rec[i] == 1:
			q.append(i)
	lst = q.pop()
	res = []
	while q:
		nd = q.pop()
		new = []
		res.append(nd)
		for nex in gp[nd]:
			rec[nex] -= 1
			if rec[nex] == 1:
				new.append(nex)
		new.sort(key=lambda a: crec[a])
		q.extend(new)
	res.append(lst)
	print(*res)
main()


from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
mod = 10 ** 9 + 7
eps = 10 ** (-7)

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

def inpl(k=0):
	return [int(x) + k for x in sys.stdin.readline().split()]

def inpl_str():
	return list(sys.stdin.readline().split())
N = inp()
aa = [inpl(-1) for _ in range(N - 2)]
cnts = [set() for _ in range(N)]
for (i, (a1, a2, a3)) in enumerate(aa):
	cnts[a1].add(i)
	cnts[a3].add(i)
	cnts[a2].add(i)
first = True
c2 = []
for (c, s) in enumerate(cnts):
	if len(s) == 1:
		if first:
			ai = list(s)[0]
			pp = [c]
			first = False
		else:
			last_ai = list(s)[0]
			last_p = c
	elif len(s) == 2:
		c2.append(c)
cnts[last_p].add(-1)
cnts[last_p].add(-2)
for c in c2:
	if last_ai in cnts[c]:
		cnts[c].add(-1)
		last_2p = c
for _ in range(N - 3):
	for ci in aa[ai]:
		cnts[ci].remove(ai)
		if len(cnts[ci]) == 1:
			next_ai = list(cnts[ci])[0]
			pp.append(ci)
	ai = next_ai
pp += [last_2p, last_p]
print(' '.join([str(p + 1) for p in pp]))


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
n = int(input())
a = [arrIN() for _ in range(n - 2)]
d = [0] * (n + 1)
pos = defaultdict(list)
for i in range(n - 2):
	for j in a[i]:
		d[j] += 1
		pos[j].append(i)
ans = []
flag = [1] * (n - 2)
for i in range(1, n + 1):
	if d[i] == 1:
		x = a[pos[i][0]]
		flag[pos[i][0]] = 0
		break
t = [0, 0, 0]
for i in x:
	if d[i] == 1:
		t[0] = i
	elif d[i] == 2:
		t[1] = i
	else:
		t[2] = i
ans = t
l = 3
while l != n:
	for i in pos[ans[-2]]:
		if flag[i]:
			if ans[-1] in a[i]:
				x = a[i]
				flag[i] = 0
				break
	t = [i for i in x]
	t.remove(ans[-2])
	t.remove(ans[-1])
	ans.append(t[0])
	l += 1
print(*ans)


n = int(input())
arr = []
freq = [0 for i in range(n + 1)]
for i in range(n - 2):
	s = list(map(int, input().split()))
	arr.append(s)
	for j in s:
		if type(freq[j]) != list:
			freq[j] = []
		freq[j].append(i)
(start, end) = (-1, -1)
for i in range(1, n + 1):
	if len(freq[i]) == 1:
		if start == -1:
			start = i
		else:
			end = i
			break
print(start, end=' ')
done = {freq[start][0]}
last_triplet = arr[freq[start][0]]
cnt = 1
while cnt != n - 3:
	for t in last_triplet:
		to_check = set(freq[t]) - done
		if len(to_check) == 1:
			idx = next(iter(to_check))
			print(t, end=' ')
			last_triplet = arr[idx]
			done.add(idx)
			cnt += 1
			break
end_triple = sorted(arr[freq[end][0]], key=lambda x: len(freq[x]), reverse=True)
print(' '.join([str(x) for x in end_triple]))


n = int(input())
w = n * [0]
z = [[] for i in range(n)]
q = []
for i in range(n - 2):
	(a, b, c) = [int(x) - 1 for x in input().split()]
	w[a] += 1
	w[b] += 1
	w[c] += 1
	q.append([a, b, c])
	z[a].append(i)
	z[b].append(i)
	z[c].append(i)
s1 = w.index(1)
for x in z[s1]:
	a = q[x]
	last = x
for x in a:
	if w[x] == 1:
		s1 = x
	elif w[x] == 2:
		s2 = x
	else:
		s3 = x
print(s1 + 1, s2 + 1, s3 + 1, end=' ')
for i in range(n - 3):
	a = z[s2]
	b = z[s3]
	for x in a:
		if x != last and b.count(x) > 0:
			ind = x
	last = ind
	for x in q[ind]:
		if x != s2 and x != s3:
			y = x
	print(y + 1, end=' ')
	(s2, s3) = [s3, y]


def find_next(j):
	if len(r) == 1:
		for e in range(len(b[j])):
			for k in q[b[j][e]]:
				if k not in r and len(b[k - 1]) == 2:
					return k
	else:
		for e in b[j]:
			for k in q[e]:
				if k not in r[-3:] and r[-2] in q[e] and (r[-1] in q[e]):
					return k
n = int(input())
q = []
b = []
r = []
for i in range(n):
	b.append([])
for i in range(n - 2):
	q.append(list(map(int, input().split())))
	b[q[i][0] - 1].append(i)
	b[q[i][1] - 1].append(i)
	b[q[i][2] - 1].append(i)
for i in range(n):
	if len(b[i]) == 1:
		break
r.append(i + 1)
i += 1
for _ in range(1, n):
	i = find_next(i - 1)
	r.append(i)
print(*r)


from sys import *
input = stdin.readline
from bisect import *
import math
from collections import *
from heapq import *
from itertools import *
inf = 10 ** 18
mod = 10 ** 9 + 7
n = int(input())
n1 = n - 2
d = {}
d1 = {}
visit = {}
l1 = []
for i in range(1, n + 1):
	d[i] = []
	d1[i] = 0
	visit[i] = False
while n1:
	n1 -= 1
	(a, b, c) = map(int, input().split())
	d[a].append(b)
	d[a].append(c)
	d1[a] += 1
	d[b].append(a)
	d[b].append(c)
	d1[b] += 1
	d[c].append(b)
	d[c].append(a)
	d1[c] += 1
d1 = dict(sorted(d1.items(), key=lambda x: x[1]))
for i in d1:
	if visit[i] == 0:
		l1.append(i)
		visit[i] = 1
	x = sorted(d[i], key=lambda x: d1[x])
	for j in x:
		if visit[j] == 0:
			l1.append(j)
			visit[j] = 1
			x.extend(d[j])
print(*l1)


import sys
input = sys.stdin.readline
n = int(input())
triple = []
indexes = [[] for _ in range(n)]
cnt = [0] * n
abc = []
for i in range(n - 2):
	(a, b, c) = [int(item) - 1 for item in input().split()]
	abc.append((a, b, c))
	indexes[a].append(i)
	indexes[b].append(i)
	indexes[c].append(i)
	cnt[a] += 1
	cnt[b] += 1
	cnt[c] += 1
tmp = cnt[:]
ans = []
node = cnt.index(1)
visited = [0] * (n - 2)
nxt = indexes[node][0]
while True:
	for item in indexes[node]:
		if visited[item]:
			continue
		nxt = item
		visited[nxt] = 1
	(a, b, c) = abc[nxt]
	if cnt[a] == 1 and cnt[b] == 1 and (cnt[c] == 1):
		break
	ans.append(node + 1)
	cnt[a] -= 1
	cnt[b] -= 1
	cnt[c] -= 1
	if cnt[a] == 1:
		node = a
	elif cnt[b] == 1:
		node = b
	elif cnt[c] == 1:
		node = c
for item in abc[nxt]:
	if tmp[item] == 3:
		ans.append(item + 1)
for item in abc[nxt]:
	if tmp[item] == 2:
		ans.append(item + 1)
for item in abc[nxt]:
	if tmp[item] == 1:
		ans.append(item + 1)
print(' '.join([str(item) for item in ans]))


n = int(input())
k = 3
n1 = n - k + 1
d = {}
d1 = {}
visit = {}
l1 = []
for i in range(1, n + 1):
	d[i] = []
	d1[i] = 0
	visit[i] = False
while n1:
	n1 -= 1
	l = list(map(int, input().split()))
	for i in range(len(l)):
		d1[l[i]] += 1
		for j in range(len(l)):
			if j == i:
				continue
			d[l[i]].append(l[j])
d1 = dict(sorted(d1.items(), key=lambda x: x[1]))
for i in d1:
	if not visit[i]:
		visit[i] = True
		l1.append(i)
		x = sorted(d[i], key=lambda x: d1[x])
		for j in x:
			if not visit[j]:
				visit[j] = True
				l1.append(j)
				x += d[j]
	if len(l1) == n:
		break
print(*l1)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, sys
from sys import stdin, stdout

def modinv(n, p):
	return pow(n, p - 2, p)

def nc():
	return map(int, ns().split())

def narr():
	return list(map(int, ns().split()))

def ns():
	return input()

def ni():
	return int(input())
n = ni()
P = collections.defaultdict(list)
I = [[] for i in range(n + 1)]
tuples = []
for i in range(n - 2):
	q = sorted(narr())
	tuples.append(q)
	P[q[0], q[1]].append(i)
	P[q[1], q[2]].append(i)
	P[q[0], q[2]].append(i)
	I[q[0]].append(i)
	I[q[1]].append(i)
	I[q[2]].append(i)
current_element = 0
current_tuple_index = -1
for i in range(n):
	if len(I[i]) == 1:
		current_element = i
		current_tuple_index = I[i][0]
		break

def sort_tuple_given_first(p, x, y):
	p1 = (min(p, x), max(p, x))
	p2 = (min(p, y), max(p, y))
	if len(P[p1]) == 2:
		return [p, x, y]
	else:
		return [p, y, x]
	return t

def sort_tuple_given_third(a, b, c):
	return list(reversed(sort_tuple_given_first(c, b, a)))

def setdiff(x, y):
	return sorted(list(set(x).difference(set(y))))

def x_exists_without_y_z(x, y, z):
	for i in I[x]:
		if y not in tuples[i] and z not in tuples[i]:
			return True
	return False

def sort_first_tuple_given_first(x, y, z):
	if x_exists_without_y_z(y, x, z):
		return [x, z, y]
	else:
		return [x, y, z]
first_pair = setdiff(tuples[current_tuple_index], [current_element])
current_tuple = sort_first_tuple_given_first(current_element, first_pair[0], first_pair[1])
answer = current_tuple.copy()
for t in range(n - 3):
	pair = setdiff(current_tuple, [current_element])
	possible_tuple_indexes = I[pair[0]]
	for i in possible_tuple_indexes:
		if pair[1] in tuples[i] and current_element not in tuples[i]:
			current_tuple_index = i
			break
	next_tuple = tuples[current_tuple_index]
	third_element = setdiff(next_tuple, current_tuple)[0]
	first_two_elements = setdiff(next_tuple, [third_element])
	next_tuple = sort_tuple_given_third(first_two_elements[0], first_two_elements[1], third_element)
	current_tuple = next_tuple
	current_element = current_tuple[0]
	answer.append(current_tuple[2])
print(' '.join(map(str, answer)))


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = []
cnt = [0] * n
groups = [[] for i in range(n)]
for i in range(n - 2):
	a.append([int(i) - 1 for i in input().split()])
	for j in a[-1]:
		cnt[j] += 1
		groups[j].append(i)
dissolved = [0] * n
ind = cnt.index(1)
cnt1 = cnt[:]
ans = []
temp = 0
last = n - cnt[::-1].index(1)
while temp < n - 2:
	ans.append(ind + 1)
	for i in groups[ind]:
		if dissolved[i] != 1:
			for j in a[i]:
				cnt[j] -= 1
				if cnt[j] == 1:
					ind = j
			dissolved[i] = 1
			temp += 1
ans.append(last)
for i in range(n - 1):
	cnt[ans[i] - 1] += 1
ans.append(cnt.index(0) + 1)
(ans[-1], ans[-2]) = (ans[-2], ans[-1])
if cnt1[ans[-2] - 1] == 3:
	(ans[-2], ans[-3]) = (ans[-3], ans[-2])
print(*ans)


from collections import defaultdict
n = int(input())
nei = defaultdict(list)
q = []
for i in range(n - 2):
	(a, b, c) = map(lambda x: int(x) - 1, input().split())
	q.append((a, b, c))
	nei[tuple(sorted((a, b)))].append(c)
	nei[tuple(sorted((a, c)))].append(b)
	nei[tuple(sorted((b, c)))].append(a)
counts = [0] * n
for (a, b, c) in q:
	counts[a] += 1
	counts[b] += 1
	counts[c] += 1
start = next(filter(lambda i: counts[i] == 1, range(n)))
for abc in q:
	if start in abc:
		break
(a, b, c) = abc
if b == start:
	(a, b) = (b, a)
elif c == start:
	(a, c) = (c, a)
if counts[b] != 2:
	(b, c) = (c, b)
p = [a, b, c]
while len(p) < n:
	candidates = nei[tuple(sorted((p[-2], p[-1])))]
	ne = candidates[0]
	if candidates[0] == p[-3]:
		ne = candidates[1]
	p.append(ne)
print(*[x + 1 for x in p])


n = int(input())
trip = {}
cnt = [0] * (n + 1)
for i in range(n - 2):
	(p1, p2, p3) = sorted(map(int, input().split()))
	if (p1, p2) in trip:
		trip[p1, p2].append(p3)
	else:
		trip[p1, p2] = [p3]
	if (p1, p3) in trip:
		trip[p1, p3].append(p2)
	else:
		trip[p1, p3] = [p2]
	if (p2, p3) in trip:
		trip[p2, p3].append(p1)
	else:
		trip[p2, p3] = [p1]
	cnt[p1] += 1
	cnt[p2] += 1
	cnt[p3] += 1
start = min(range(1, n + 1), key=lambda x: cnt[x])
answer = [start]
for pr in trip:
	pr = (pr, trip[pr])
	if start in pr[1]:
		if cnt[pr[0][1]] == 2:
			answer.append(pr[0][1])
			answer.append(pr[0][0])
		else:
			answer.append(pr[0][0])
			answer.append(pr[0][1])
was = [False] * (n + 1)
was[answer[0]] = was[answer[1]] = was[answer[2]] = True
cur = answer[1:]
for i in range(n - 3):
	mp = tuple(cur)
	if mp not in trip:
		mp = tuple(reversed(mp))
	val = trip[mp]
	if not was[val[0]]:
		answer.append(val[0])
		was[val[0]] = True
		cur = [cur[1], val[0]]
	elif len(val) > 1:
		answer.append(val[1])
		was[val[1]] = True
		cur = [cur[1], val[1]]
print(' '.join(map(str, answer)))


n = int(input())
Q = []
for i in range(n - 2):
	Q.append(list(map(int, input().split())))
d = {i + 1: [] for i in range(n)}
for qindex in range(len(Q)):
	d[Q[qindex][0]].append(qindex)
	d[Q[qindex][1]].append(qindex)
	d[Q[qindex][2]].append(qindex)
for num in d.keys():
	if len(d[num]) == 1:
		p = [num]
		n -= 1
		lastnums = [num]
		break
for i in Q[d[lastnums[0]][0]]:
	if len(d[i]) == 2:
		p.append(i)
		n -= 1
		lastnums.append(i)
		lastnums.append([j for j in Q[d[lastnums[0]][0]] if j not in lastnums][0])
		break

def func():
	global lastnums
	global p
	global n
	global d
	n -= 1
	p.append(lastnums[2])
	for i in d[lastnums[2]]:
		if lastnums[1] in Q[i] and lastnums[2] in Q[i] and (lastnums[0] not in Q[i]):
			lastnums = [lastnums[1], lastnums[2], [j for j in Q[i] if j not in lastnums][0]]
			break
while n:
	func()
print(' '.join(map(str, p)))


from collections import defaultdict
n = int(input())
tups = []
where = defaultdict(list)
for i in range(n - 2):
	(a, b, c) = list(map(int, input().strip().split()))
	where[a].append(i)
	where[b].append(i)
	where[c].append(i)
	tups.append([a, b, c])
ans = [-1] * n
for i in range(1, n + 1):
	if len(where[i]) == 1:
		if ans[0] == -1:
			ans[0] = i
			(nx1, nx2) = [nx for nx in tups[where[i][0]] if nx != i]
			if len(where[nx1]) == 2:
				ans[1] = nx1
			else:
				ans[1] = nx2
		else:
			ans[n - 1] = i
			(nx1, nx2) = [nx for nx in tups[where[i][0]] if nx != i]
			if len(where[nx1]) == 2:
				ans[n - 2] = nx1
			else:
				ans[n - 2] = nx2
	done = {ans[0]: 1, ans[1]: 1}
for i in range(2, n):
	nxt_ind = list(set(where[ans[i - 1]]).intersection(set(where[ans[i - 2]])))
	for ind in nxt_ind:
		for ele in tups[ind]:
			if ele not in done:
				ans[i] = ele
				done[ele] = 1
for i in ans:
	print(i, end=' ')
print()


n = int(input())
vis = [0] * (n + 1)
c = [0] * (n + 1)
from collections import defaultdict
d = defaultdict(list)
for i in range(n - 2):
	(a, b, e) = list(map(int, input().split()))
	c[a] += 1
	c[b] += 1
	c[e] += 1
	d[a].extend([a, b, e])
	d[b].extend([a, b, e])
	d[e].extend([a, b, e])
res = []
for i in range(1, n + 1):
	if c[i] == 1:
		res.append(i)
		vis[i] = 1
		break
k = 1
while k < n:
	if c[res[-1]] == 3:
		ar = {}
		for j in d[res[-1]]:
			if j in ar:
				ar[j] += 1
			else:
				ar[j] = 1
		for j in ar:
			if ar[j] == 2 and vis[j] == 0:
				res.append(j)
				vis[j] = 1
	elif c[res[-1]] == 1:
		for i in d[res[-1]]:
			if c[i] == 2:
				res.append(i)
				vis[i] = 1
				break
	else:
		ar = {}
		if k == 2:
			for j in d[res[-1]]:
				if j in ar:
					ar[j] += 1
				else:
					ar[j] = 1
			for j in ar:
				if ar[j] == 2 and vis[j] == 0:
					res.append(j)
					vis[j] = 1
		else:
			for i in d[res[-1]]:
				if c[i] == 1:
					res.append(i)
					vis[i] = 1
					break
	k += 1
print(*res)


n = int(input())
dic = {}
for i in range(n):
	dic[i + 1] = []
for i in range(n - 2):
	li = list(map(int, input().split()))
	dic[li[0]].append(li)
	dic[li[1]].append(li)
	dic[li[2]].append(li)
one = []
two = []
for i in range(n):
	if len(dic[i + 1]) == 1:
		one.append(i + 1)
	elif len(dic[i + 1]) == 2:
		two.append(i + 1)
print(one[0], end=' ')
for i in dic[one[0]][0]:
	if i in two:
		print(i, end=' ')
		break
for j in dic[one[0]][0]:
	if j != one[0] and j != i:
		c = j
a = one[0]
b = i
print(c, end=' ')
for zz in range(n - 2):
	for m in dic[b]:
		if m in dic[c] and (not a in m):
			a = b
			b = c
			c = sum(m) - (a + b)
			print(c, end=' ')
			break


import math
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 = dict()
d1 = dict()
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	if (min(a, b), max(a, b)) in d:
		d[min(a, b), max(a, b)].append(c)
	else:
		d.update({(min(a, b), max(a, b)): [c]})
	if (min(c, b), max(c, b)) in d:
		d[min(c, b), max(c, b)].append(a)
	else:
		d.update({(min(c, b), max(c, b)): [a]})
	if (min(a, c), max(a, c)) in d:
		d[min(a, c), max(a, c)].append(b)
	else:
		d.update({(min(a, c), max(a, c)): [b]})
	if a in d1:
		d1[a] += 1
	else:
		d1.update({a: 1})
	if b in d1:
		d1[b] += 1
	else:
		d1.update({b: 1})
	if c in d1:
		d1[c] += 1
	else:
		d1.update({c: 1})
ans = []
for i in range(1, n + 1):
	if d1[i] == 1:
		ans.append(i)
		st = i
		break
for i in range(1, n + 1):
	if d1[i] == 2 and (min(i, st), max(i, st)) in d:
		ans.append(i)
s = set(ans)
for i in range(2, n):
	for j in d[min(ans[i - 2], ans[i - 1]), max(ans[i - 2], ans[i - 1])]:
		if j in s:
			continue
		ans.append(j)
		s.add(j)
print(*ans, sep=' ')


n = int(input())
lst = []
nums = []
ans = []
looking_for = []
looking_for1 = []
looking_for2 = []
last_triple_index = -1
triple_index = [False] * (n + 10)
triple_indexxx = []
for i in range(n + 1):
	nums.append([])
for i in range(n - 2):
	lst.append(list(map(int, input().split())))
	for j in range(3):
		nums[lst[i][j]].append(i)
for i in range(1, n + 1):
	if len(nums[i]) == 1:
		ans.append(i)
		looking_for = []
		for j in range(3):
			if lst[nums[i][0]][j] != i:
				looking_for.append(lst[nums[i][0]][j])
				triple_index[nums[i][0]] = True
				triple_indexxx.append(nums[i][0])
				done = i
		break
while len(ans) < n - 3:
	looking_for1 = []
	looking_for2 = []
	for j in range(len(nums[looking_for[0]])):
		triple_i = nums[looking_for[0]][j]
		if triple_i in nums[looking_for[1]] and (not triple_index[triple_i]):
			triple_index[triple_i] = True
			triple_indexxx.append(triple_i)
			for k in range(3):
				if lst[triple_i][k] not in looking_for:
					looking_for1.append(lst[triple_i][k])
					looking_for2.append(lst[triple_i][k])
					yeah = lst[triple_i][k]
			for k in range(3):
				if lst[triple_i][k] not in looking_for1 and len(looking_for1) < 2 and (lst[triple_i][k] != yeah):
					looking_for1.append(lst[triple_i][k])
				elif lst[triple_i][k] != yeah:
					looking_for2.append(lst[triple_i][k])
	found = False
	for j in range(len(nums[looking_for1[0]])):
		triple_i = nums[looking_for1[0]][j]
		if triple_i in nums[looking_for1[1]] and (not triple_index[triple_i]):
			for i in range(2):
				if looking_for2[i] not in looking_for1:
					ans.append(looking_for2[i])
					break
			looking_for = looking_for1
			found = True
	if not found:
		for j in range(len(nums[looking_for2[0]])):
			triple_i = nums[looking_for2[0]][j]
			if triple_i in nums[looking_for2[1]] and (not triple_index[triple_i]):
				for i in range(2):
					if looking_for1[i] not in looking_for2:
						ans.append(looking_for1[i])
						break
				looking_for = looking_for2
				found = True
current = triple_indexxx[-2]
for i in range(2):
	if looking_for[i] in lst[current]:
		ans.append(looking_for[i])
		looking_for[i] = None
for i in range(2):
	if looking_for[i] is not None:
		ans.append(looking_for[i])
for i in range(1, n + 1):
	if len(nums[i]) == 1 and i not in ans:
		ans.append(i)
		looking_for = []
		for j in range(3):
			if lst[nums[i][0]][j] != i:
				looking_for.append(lst[nums[i][0]][j])
				triple_index.append(nums[i][0])
				done = i
		break
for i in range(len(ans)):
	print(ans[i], end=' ')


from sys import stdin

def rl():
	return [int(w) for w in stdin.readline().split()]
n = int(stdin.readline())
dem = [0] * (n + 1)
p = dict()
for i in range(n - 2):
	(a, b, c) = rl()
	dem[a] += 1
	dem[b] += 1
	dem[c] += 1
	t1 = (min(a, b), max(a, b))
	t2 = (min(a, c), max(a, c))
	t3 = (min(b, c), max(b, c))
	if t1 not in p:
		p[t1] = [0, 0]
		p[t1][0] = c
	else:
		p[t1][1] = c
	if t2 not in p:
		p[t2] = [0, 0]
		p[t2][0] = b
	else:
		p[t2][1] = b
	if t3 not in p:
		p[t3] = [0, 0]
		p[t3][0] = a
	else:
		p[t3][1] = a
(root, root1) = (int, int)
for i in range(1, n + 1):
	if dem[i] == 1:
		root = i
		break
for i in range(1, n + 1):
	if dem[i] == 2 and (min(i, root), max(i, root)) in p:
		root1 = i
		break
res = []
check = [1] * (n + 1)
res.append(root)
res.append(root1)
check[root] = 0
check[root1] = 0
i = 1
while i < n - 1:
	t1 = (min(res[i], res[i - 1]), max(res[i - 1], res[i]))
	tmp1 = p[t1][0]
	tmp2 = p[t1][1]
	if check[tmp1] == 0:
		res.append(tmp2)
	else:
		res.append(tmp1)
	i += 1
	check[res[i]] = 0
for x in res:
	print(x, end=' ')


def main():
	global visited, adj, sets
	print = out.append
	n = get_int()
	triplets = []
	presence = [[] for _ in range(n)]
	for index in range(n - 2):
		li = list(sorted(get_list()))
		triplets.append(li)
		for i in li:
			presence[i - 1].append(index)
	res = []
	for (i, li) in enumerate(presence):
		if len(li) == 1:
			triplet = triplets[li[0]]
			c = li[0]
			res.append(i + 1)
			for ele in triplet:
				if len(presence[ele - 1]) == 2:
					res.append(ele)
					a = ele
					break
			for ele in triplet:
				if ele not in res:
					res.append(ele)
					b = ele
			for _ in range(n - 3):
				index = list(set(presence[a - 1]).intersection(set(presence[b - 1])))
				index.remove(c)
				c = index[0]
				triplet = triplets[c]
				for i in triplet:
					if not (i == a or i == b):
						a = b
						b = i
						res.append(i)
						break
			break
	print(' '.join(map(str, res)))
import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
main()
print(*out, sep='\n')


from sys import stdin
input = stdin.readline
n = int(input())
pos = [[] for _ in range(n + 1)]
t = [[]]
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	pos[a].append(i + 1)
	pos[b].append(i + 1)
	pos[c].append(i + 1)
	t.append((a, b, c))
start = []
for i in range(1, n + 1):
	if len(pos[i]) == 1:
		start.append(i)
		break
now = pos[start[0]][0]
(a, b) = (0, 0)
for i in range(0, 3):
	if len(pos[t[now][i]]) == 2:
		a = t[now][i]
	elif len(pos[t[now][i]]) == 3:
		b = t[now][i]
start.append(a)
start.append(b)
nxt = pos[a][0] if pos[a][0] != now else pos[a][1]
while True:
	for i in range(3):
		if t[nxt][i] != a and t[nxt][i] != b:
			start.append(t[nxt][i])
			a = b
			b = t[nxt][i]
			break
	nnxt = 0
	for x in pos[a]:
		if x != now and x != nxt:
			nnxt = x
			break
	if nnxt == 0:
		break
	now = nxt
	nxt = nnxt
print(*start)


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

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

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = 1
	mod = 998244353
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		n = inp()
		mapping = [[] for i in range(n + 1)]
		for i in range(n - 2):
			[q1, q2, q3] = inlt()
			mapping[q1].append([q2, q3])
			mapping[q2].append([q1, q3])
			mapping[q3].append([q2, q1])
		ans = []
		for i in range(n + 1):
			if len(mapping[i]) == 1:
				ans.append(i)
				break
		[q1, q2] = mapping[ans[0]][0]
		if len(mapping[q1]) == 2:
			ans.append(q1)
			ans.append(q2)
		else:
			ans.append(q2)
			ans.append(q1)
		for i in range(1, n - 2):
			for j in mapping[ans[i]]:
				if ans[i - 1] not in j:
					if j[0] == ans[i + 1]:
						ans.append(j[1])
					else:
						ans.append(j[0])
					break
		pr_list(ans)
main()


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
N = 10 ** 10 + 7

def fin(x, y, j):
	p = [i for i in x if i in y]
	return p[0] if p[0] != j else p[-1]
n = I()
a = [[] for i in range(n + 1)]
v = []
for i in range(n - 2):
	v.append(L())
	for el in v[-1]:
		a[el] += (i,)
ans = []
for i in range(n):
	if len(a[i + 1]) == 1:
		ans += (i + 1,)
		m = v[a[i + 1][0]]
		m.remove(i + 1)
		if len(a[m[0]]) == 2:
			ans.extend([m[0], m[1]])
		else:
			ans.extend([m[1], m[0]])
		ln = 3
		pr = a[i + 1][0]
		while ln < n:
			ind = fin(a[ans[-1]], a[ans[-2]], pr)
			for el in v[ind]:
				if el not in ans[ln - 2:]:
					ans += (el,)
					break
			pr = ind
			ln += 1
		break
print(*ans)


def check(l1, l2, c):
	for i in range(c):
		if l1[i] == l2[i] and l1[len(l1) - 1 - i] == l2[len(l1) - 1 - i]:
			continue
		else:
			print(l1[i], l2[i], 'False', i)
			return False
	return True
n = int(input())
k = 3
adjacent = {}
occurrence = {}
visit = {}
A = []
nodes = []
for node in range(1, n + 1):
	adjacent[node] = set()
	occurrence[node] = 0
	visit[node] = False
for _ in range(n - k + 1):
	q = list(map(int, input().split()))
	for i in range(k):
		occurrence[q[i]] += 1
		for j in range(k):
			if j == i:
				continue
			adjacent[q[i]].add(q[j])
occurrence = dict(sorted(occurrence.items(), key=lambda x: x[1]))
for node in occurrence:
	if not visit[node]:
		visit[node] = True
		A.append(node)
		children = sorted(adjacent[node], key=lambda x: occurrence[x])
		for child in children:
			if not visit[child]:
				visit[child] = True
				A.append(child)
				children += adjacent[child]
		nodes.append(node)
	if len(A) == n:
		break
print(*A)


n = int(input())
triples = []
links = [[] for _ in range(n)]
for i in range(n - 2):
	(a, b, c) = triple = [int(x) for x in input().split()]
	links[a - 1].append(i)
	links[b - 1].append(i)
	links[c - 1].append(i)
	triples.append(sorted(triple))
xs = []
for (i, link) in enumerate(links, 1):
	if len(link) == 1:
		current = i
		ind = link[0]
		break
(a, b, c) = sorted(triples[ind], key=lambda x: len(links[x - 1]))
xs += [a, b, c]
current = b

def union(b, c, ind):
	return [x for x in links[b - 1] if x in links[c - 1] and x != ind][0]
while len(xs) < n:
	new_ind = union(b, c, ind)
	missing = [x for x in triples[new_ind] if x not in (b, c)][0]
	xs.append(missing)
	(b, c) = (c, missing)
	ind = new_ind
print(*xs)


import math
N = int(input())
val = [list(map(int, input().split())) for i in range(N - 2)]
ct = [[] for i in range(N)]
for i in range(N - 2):
	for j in val[i][:]:
		ct[j - 1].append(i)
rank = []
for i in range(N):
	if len(ct[i]) == 1:
		rank.append(i)
		A = val[ct[i][0]]
		for j in A:
			if len(ct[j - 1]) == 2:
				rank.append(j - 1)
		temp = list(set(A) ^ set([rank[0] + 1, rank[1] + 1]))
		rank.append(temp[0])
		rank[2] = rank[2] - 1
		break
for i in range(N - 3):
	A = ct[rank[-3]]
	B = ct[rank[-2]]
	c = set(A) & set(B)
	d = list(set(B) ^ c)
	e = list(set(val[d[0]]) ^ set([rank[-1] + 1, rank[-2] + 1]))
	rank.append(e[0] - 1)
for i in range(N):
	if i == N - 1:
		print(rank[i] + 1)
	else:
		print(rank[i] + 1, end=' ')


import sys

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

def getFirstValue(mapValToTripletsIndex):
	for t in range(0, n):
		if len(mapValToTripletsIndex[t]) == 1:
			return t

def cleanupUsedTriplet(mapValToTripletsIndex, index, triplets):
	for t in triplets[index]:
		mapValToTripletsIndex[t].remove(index)
n = int(input())
triplets = []
mapValToTripletsIndex = [[] for i in range(0, n + 1)]
for index in range(n - 2):
	triplet = list(map(int, input().split()))
	triplets.append(triplet)
	for val in triplet:
		mapValToTripletsIndex[val].append(index)
ans = []
firstVal = getFirstValue(mapValToTripletsIndex)
firstTripletIndex = mapValToTripletsIndex[firstVal][0]
firstTriplet = triplets[firstTripletIndex]
for val in firstTriplet:
	if val != firstTriplet and len(mapValToTripletsIndex[val]) == 2:
		secondVal = val
	if val != firstTriplet and len(mapValToTripletsIndex[val]) == 3:
		thirdVal = val
ans = [firstVal, secondVal, thirdVal]
cleanupUsedTriplet(mapValToTripletsIndex, firstTripletIndex, triplets)
for i in range(0, n - 3):
	val1 = ans[-1]
	val2 = ans[-2]
	index = list(set(mapValToTripletsIndex[val1]) & set(mapValToTripletsIndex[val2]))[0]
	val3 = list(set(triplets[index]) - {val1, val2})[0]
	ans.append(val3)
	cleanupUsedTriplet(mapValToTripletsIndex, index, triplets)
print(' '.join(map(str, ans)))


import sys
input = sys.stdin.readline
dg = 10 ** 12
dg2 = 10 ** 6
n = int(input())
idx = [[] for i in range(n + 1)]
q = []
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	q.append((a, b, c))
	idx[a].append(i)
	idx[b].append(i)
	idx[c].append(i)
sta = -1
ne = -1
for i in range(1, n + 1):
	if len(idx[i]) == 1:
		sta = i
		break
for e in q[idx[sta][0]]:
	if len(idx[e]) == 2:
		ne = e
		break
num = idx[sta][0]
res = [sta, ne]
for i in range(n - 2):
	for e in q[num]:
		if not e in (sta, ne):
			sta = ne
			ne = e
			break
	res.append(ne)
	if i == n - 3:
		break
	nums = set(idx[sta]) & set(idx[ne])
	for e in nums:
		if e != num:
			num = e
			break
print(*res)


n = int(input())
arr = [None] * (n - 2)
d = dict()
nearby = dict()
for i in range(n - 2):
	arr[i] = list(map(int, input().split()))
	for j in range(3):
		try:
			nearby[arr[i][j]].add(arr[i][(j + 1) % 3])
		except:
			nearby[arr[i][j]] = set([arr[i][(j + 1) % 3]])
		try:
			nearby[arr[i][j]].add(arr[i][(j + 2) % 3])
		except:
			nearby[arr[i][j]] = set([arr[i][(j + 2) % 3]])
	for j in arr[i]:
		if j in d:
			d[j] += 1
		else:
			d[j] = 1
d1 = dict()
for i in d:
	try:
		d1[d[i]].add(i)
	except:
		d1[d[i]] = set([i])
ans = []
last = []
aagye = set()
j = 0
for i in d1[1]:
	if j % 2 == 0:
		ans.append(i)
		aagye.add(i)
	else:
		last.append(i)
	j += 1
for i in d1[2]:
	if i in nearby[ans[0]]:
		ans.append(i)
		aagye.add(i)
	else:
		last.append(i)
for i in range(n - 4):
	lol = nearby[ans[-1]] & nearby[ans[-2]]
	for k in lol:
		if k not in aagye:
			ans.append(k)
			aagye.add(k)
print(*ans, *last[::-1])


from collections import defaultdict

def Fir3():
	global final, d, ones
	for i in d[ones]:
		(x, y) = i if len(d[i[0]]) == 2 else i[::-1]
		final.extend([x, y])
		if (ones, y) in d[x]:
			d[x].remove((ones, y))
		else:
			d[x].remove((y, ones))
		if (ones, x) in d[y]:
			d[y].remove((ones, x))
		else:
			d[y].remove((x, ones))
n = int(input())
d = defaultdict(list)
for i in range(n - 2):
	(v1, v2, v3) = map(int, input().split())
	d[v1].append((v2, v3))
	d[v2].append((v1, v3))
	d[v3].append((v2, v1))
ones = 0
for i in range(1, n + 1):
	if len(d[i]) == 1:
		ones = i
		break
final = [ones]
Fir3()
for i in range(1, n - 2):
	(x, y) = (final[i], final[i + 1])
	for j in d[x]:
		z = j[0] if j[1] == y else j[1]
		final.append(z)
		if (x, y) in d[z]:
			d[z].remove((x, y))
		else:
			d[z].remove((y, x))
		if (x, z) in d[y]:
			d[y].remove((x, z))
		else:
			d[y].remove((z, x))
print(*final)


import math
import random

def l_perm(n, q):
	seen = [False for i in range(n + 1)]
	binding = [[] for i in range(n + 1)]
	freq = [0 for i in range(n + 1)]
	m = len(q)
	for i in range(m):
		x = q[i][0]
		y = q[i][1]
		z = q[i][2]
		binding[x].append(y)
		binding[x].append(z)
		binding[y].append(x)
		binding[y].append(z)
		binding[z].append(x)
		binding[z].append(y)
		freq[x] += 1
		freq[y] += 1
		freq[z] += 1
	f = None
	s = None
	for i in range(n + 1):
		if freq[i] == 1:
			f = i
			break
	if freq[binding[f][0]] == 2:
		s = binding[f][0]
	else:
		s = binding[f][1]
	p = [str(f), str(s)]
	seen[f] = True
	seen[s] = True
	i = 2
	t = None
	while i < n:
		for e in binding[f]:
			if seen[e] == False:
				t = e
				break
		p.append(str(t))
		seen[t] = True
		f = s
		s = t
		i += 1
	return ' '.join(p)

def generate_test_case(n=10):
	p = [i for i in range(1, n + 1)]
	random.shuffle(p)
	q = []
	for i in range(2, n):
		w = p[i - 2:i + 1]
		random.shuffle(w)
		q.append(w)
	return (p, q)
n = int(input())
q = [[0, 0, 0] for i in range(n - 2)]
for i in range(n - 2):
	s = input().split(' ')
	s = [int(j) for j in s]
	q[i] = s
ep = l_perm(n, q)
print(ep)


def get_common(a, b, boolar, d):
	(i, j) = (0, 0)
	while d[a][i] != d[b][j] or boolar[d[a][i]] == False:
		if d[a][i] < d[b][j]:
			i += 1
		else:
			j += 1
	return d[a][i]
t = 1
for i in range(t):
	n = int(input())
	x = []
	d = {}
	boolar = [True for i in range(n - 2)]
	for i in range(1, n + 1):
		d[i] = []
	for i in range(n - 2):
		(q1, q2, q3) = map(int, input().split())
		x.append([q1, q2, q3])
		d[q1].append(i)
		d[q2].append(i)
		d[q3].append(i)
	for i in d:
		if len(d[i]) == 1:
			break
	first = i
	target = d[i][0]
	boolar[target] = False
	for j in x[target]:
		if len(d[j]) == 2:
			second = j
		if len(d[j]) == 3:
			third = j
	ans = [first, second, third]
	i = 1
	while i < n - 2:
		target = get_common(ans[-1], ans[-2], boolar, d)
		boolar[target] = False
		for j in x[target]:
			if j != ans[-1] and j != ans[-2]:
				ans.append(j)
				break
		i += 1
	print(*ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import 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')

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 types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

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

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

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

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 ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	n = int(inp())
	q = []
	hash = {}
	for i in range(n - 2):
		temp = lis()
		for j in range(3):
			if temp[j] not in hash:
				hash[temp[j]] = [temp]
			else:
				hash[temp[j]].append(temp)
	ind = 0
	ans = [0] * n
	for val in range(1, n + 1):
		if len(hash[val]) == 1:
			ans[ind] = val
			ind += 1
			curr = hash[val][0]
			break
	for val in range(1, n + 1):
		if len(hash[val]) == 2 and val in curr:
			ans[ind] = val
			ind += 1
			break
	while ind < n:
		temp = hash[ans[ind - 2]]
		for j in range(len(temp)):
			if ans[ind - 1] in temp[j]:
				for i in range(3):
					if temp[j][i] != ans[ind - 1] and temp[j][i] != ans[ind - 2]:
						ans[ind] = temp[j][i]
						hash[ans[ind]].remove(temp[j])
						hash[ans[ind - 1]].remove(temp[j])
						hash[ans[ind - 2]].remove(temp[j])
						ind += 1
						break
				break
	print(' '.join((str(ans[i]) for i in range(n))))
testcase(1)


import sys
input = sys.stdin.readline
from collections import defaultdict as dd
n = int(input())
l = []
cc = [0] * (n + 1)
d = dd(list)
res = []
one = []
two = []
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	l.append((a, b, c))
	cc[a] += 1
	cc[b] += 1
	cc[c] += 1
	d[a].append((a, b, c))
	d[b].append((a, b, c))
	d[c].append((a, b, c))
for i in range(len(cc)):
	if cc[i] == 1:
		one.append(i)
	if cc[i] == 2:
		two.append(i)
f = d[one[0]]
prev = [one[0]]
if cc[f[0][0]] == 2:
	prev.append(f[0][0])
if cc[f[0][1]] == 2:
	prev.append(f[0][1])
if cc[f[0][2]] == 2:
	prev.append(f[0][2])
if cc[f[0][0]] == 3:
	prev.append(f[0][0])
if cc[f[0][1]] == 3:
	prev.append(f[0][1])
if cc[f[0][2]] == 3:
	prev.append(f[0][2])
res.append(prev)
cur = []
k = n - 3
while k:
	for j in d[prev[1]]:
		if prev[2] in j and prev[0] not in j:
			f = j
			break
	prev = [prev[1], prev[2]]
	for v in j:
		if v != prev[0] and v != prev[1]:
			prev.append(v)
	res.append(prev)
	k -= 1
print(res[0][0], res[0][1], res[0][2], end=' ')
for i in range(1, len(res)):
	print(res[i][2], end=' ')


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
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())
n1 = n - 2
d = {}
d1 = {}
visit = {}
l1 = []
for i in range(1, n + 1):
	d[i] = []
	d1[i] = 0
	visit[i] = False
while n1:
	n1 -= 1
	(a, b, c) = map(int, input().split())
	d[a].append(b)
	d[a].append(c)
	d1[a] += 1
	d[b].append(a)
	d[b].append(c)
	d1[b] += 1
	d[c].append(b)
	d[c].append(a)
	d1[c] += 1
d1 = dict(sorted(d1.items(), key=lambda x: x[1]))
for i in d1:
	if visit[i] == 0:
		l1.append(i)
		visit[i] = 1
	x = sorted(d[i], key=lambda x: d1[x])
	for j in x:
		if visit[j] == 0:
			l1.append(j)
			visit[j] = 1
			x.extend(d[j])
print(*l1)


n = int(input())
s = [[int(x) - 1 for x in input().split()] for i in range(n - 2)]
l = [set() for i in range(n)]
for i in range(n - 2):
	for x in s[i]:
		l[x].add(i)
i = 0
while len(l[i]) != 1:
	i += 1
d = [True] * (n - 2)
res = []
i = list(l[i])[0]
d[i] = False

def find(a, b):
	global l, d
	tmp = l[a] & l[b]
	for i in tmp:
		if d[i]:
			return i
	return -1
isave = 0
helper = [0] * n
while True:
	tmp2 = [0] * 3
	for j in s[i]:
		helper[j] += 1
	tmp = -1
	for i1 in range(len(s[i]) - 1):
		for i2 in range(i1 + 1, len(s[i])):
			tmp = find(s[i][i1], s[i][i2])
			if tmp != -1:
				break
		if tmp != -1:
			d[tmp] = False
			break
	if tmp != -1:
		if len(res) > 1:
			for j in s[i]:
				if helper[j] == 3:
					res.append(j)
					break
		else:
			res.append(list(set(s[i]) - set(s[tmp]))[0])
		i = tmp
	else:
		tmp = [0] * 3
		for j in s[i]:
			if helper[j] == 1:
				tmp[2] = j
			elif helper[j] == 2:
				tmp[1] = j
			else:
				tmp[0] = j
		res += tmp
		break
print(*[x + 1 for x in res])


n = int(input())
ls = [0 for i in range(n)]
a = [[] for i in range(n)]
for i in range(n - 2):
	(q1, q2, q3) = map(int, input().split())
	a[q1 - 1].append(q2 - 1)
	a[q1 - 1].append(q3 - 1)
	a[q2 - 1].append(q1 - 1)
	a[q2 - 1].append(q3 - 1)
	a[q3 - 1].append(q1 - 1)
	a[q3 - 1].append(q2 - 1)
	ls[q1 - 1] += 1
	ls[q2 - 1] += 1
	ls[q3 - 1] += 1
b = []
for i in range(n):
	if ls[i] == 1:
		b.append(i)
		break
for i in range(n):
	if ls[i] == 2 and i in a[b[0]]:
		b.append(i)
		break
visited = [0 for i in range(n)]
visited[b[0]] = 1
visited[b[1]] = 1
while len(b) < n:
	u = b[-1]
	for i in range(len(a[u])):
		if visited[a[u][i]] == 0 and b[-2] in a[a[u][i]]:
			b.append(a[u][i])
			visited[a[u][i]] = 1
			break
for i in range(n):
	print(b[i] + 1, end=' ')


n = int(input())
q = []
cnt = {i: 0 for i in range(1, n + 1)}
pos = {i: [] for i in range(1, n + 1)}
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	q.append((a, b, c))
	cnt[a] += 1
	cnt[b] += 1
	cnt[c] += 1
	pos[a].append(i)
	pos[b].append(i)
	pos[c].append(i)
l = []
key = []
r = []
for i in cnt.keys():
	if cnt[i] == 1:
		key.append(i)
r.append(key[1])
for i in q[pos[r[0]][0]]:
	if cnt[i] == 2:
		r = [i] + r
		cnt[i] += 1
l.append(key[0])
j = 1
while j < n - 2:
	now = l[j - 1]
	p = pos[now][0]
	nxt = now
	for i in q[p]:
		if cnt[i] == 2:
			nxt = i
			pos[nxt].pop(pos[nxt].index(p))
			cnt[i] -= 1
	j += 1
	for i in q[p]:
		if i != nxt and i != now:
			after = i
			cnt[i] -= 1
			if j < n - 2:
				pos[i].pop(pos[i].index(p))
	l.append(nxt)
ans = l + r
print(*ans)


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')

def comp(l, r):
	for v in l:
		if v not in r:
			return v

def match(l, r):
	ans = 0
	for v in l:
		if v in r:
			ans += 1
	return ans
(n,) = gil()
tupes = []
for _ in range(n - 2):
	tupes.append(gil())
getTupleIdx = {}
for i in range(n - 2):
	for v in tupes[i]:
		if v not in getTupleIdx:
			getTupleIdx[v] = []
		getTupleIdx[v].append(i)
for i in range(1, n + 1):
	if len(getTupleIdx[i]) == 1:
		break
cTuple = tupes[getTupleIdx[i][0]]
ans = []
allowed = set(range(n - 1))
allowed.remove(getTupleIdx[i][0])
prevLen = 0
while allowed:
	fnd = False
	for v in cTuple:
		if fnd:
			break
		for idx in getTupleIdx[v]:
			if idx in allowed and match(cTuple, tupes[idx]) == 2:
				allowed.remove(idx)
				ans.append(comp(cTuple, tupes[idx]))
				cTuple = tupes[idx]
				fnd = True
				break
	if not fnd:
		cTuple.sort(reverse=True, key=lambda x: len(getTupleIdx[x]))
		for v in cTuple:
			ans.append(v)
		break
print(*ans)


n = int(input())
l = [[] for i in range(n + 1)]
trips = []
for i in range(n - 2):
	t = list(map(int, input().split()))
	trips.append(t)
	for num in t:
		l[num].append(i)
(a, b, c) = (-1, -1, -1)
for i in range(1, len(l)):
	if len(l[i]) == 1:
		a = i
		break
count = [len(l[i]) for i in range(len(l))]
p = [a]
while 1:
	count[a] = 0
	ind = l[a][0]
	trips[ind].remove(a)
	(b, c) = [x for x in trips[ind]]
	l[b].remove(ind)
	l[c].remove(ind)
	if len(l[b]) == 1 and len(l[c]) == 1:
		break
	elif len(l[b]) == 1:
		a = b
		p.append(a)
	else:
		a = c
		p.append(c)
last = [0, 0, 0]
for i in range(len(count)):
	if count[i] != 0:
		last[count[i] - 1] = i
print(*p + last[::-1])


n = int(input())
q = []
ans = []
b = [[] for x in range(n + 1)]
for i in range(n - 2):
	q.append(list(map(int, input().split())))
	for j in q[i]:
		b[j].append(i)
for i in range(1, n + 1):
	if len(b[i]) == 1:
		break
ans.append(i)
for _ in range(n - 1):
	for e in b[i]:
		for j in q[e]:
			if len(ans) == 1 and j not in ans and (len(b[j]) == 2) or (len(ans) > 1 and j not in ans[-3:] and (ans[-1] in q[e]) and (ans[-2] in q[e])):
				ans.append(j)
				i = j
print(*ans)


n = int(input())
l = []
q = n - 2
arr = [[] for i in range(n + 1)]
for i in range(q):
	(a, b, c) = map(int, input().split())
	l.append([a, b, c])
	arr[a].append(b)
	arr[a].append(c)
	arr[b].append(a)
	arr[b].append(c)
	arr[c].append(a)
	arr[c].append(b)
hash = [0] * (n + 1)
for i in range(q):
	for j in range(3):
		hash[l[i][j]] += 1
ans = []
flag = 0
for i in range(1, n + 1):
	if hash[i] == 1:
		ans.append(i)
		break
for i in range(1, n + 1):
	if hash[i] == 2 and i in arr[ans[0]]:
		ans.append(i)
		break
visited = [0] * (n + 1)
visited[ans[0]] = 1
visited[ans[1]] = 1
while len(ans) < n:
	c = ans[-1]
	for i in range(len(arr[c])):
		if visited[arr[c][i]] == 0 and ans[-2] in arr[arr[c][i]]:
			ans.append(arr[c][i])
			visited[arr[c][i]] = 1
			break
print(*ans)


import sys
input = sys.stdin.buffer.readline
n = int(input())
dicto = [dict() for i in range(n + 1)]
counted = [0] * (n + 1)
stored = []
visited = [0 for i in range(n + 1)]
start = 0
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	counted[a] += 1
	counted[b] += 1
	counted[c] += 1
	dicto[a][b] = 1
	dicto[a][c] = 1
	dicto[b][a] = 1
	dicto[b][c] = 1
	dicto[c][a] = 1
	dicto[c][b] = 1
for i in range(1, n + 1):
	if counted[i] == 1:
		start = i
		break
f_start = 0
stored.append(start)
visited[start] = 1
for j in dicto[start]:
	if counted[j] == 2:
		stored.append(j)
		break
for i in range(n - 2):
	x = stored[-1]
	y = stored[-2]
	visited[x] = 1
	for j in dicto[x]:
		if j in dicto[y] and (not visited[j]):
			stored.append(j)
			break
print(*stored)


import sys
from collections import defaultdict
input = sys.stdin.readline
n = int(input())
ctr = [0] * (n + 1)
g = defaultdict(list)
for _ in range(n - 2):
	q = [int(i) for i in input().split()]
	for i in range(3):
		v = q[i]
		ctr[v] += 1
		for j in range(i):
			to = q[j]
			g[v].append(to)
			g[to].append(v)
s = min(range(1, n + 1), key=ctr.__getitem__)
ps = [s]
visited = [False] * (n + 1)
visited[s] = True
seen = [0] * (n + 1)
for to in g[s]:
	seen[to] += 1
v = min((to for to in g[s]), key=ctr.__getitem__)
for _ in range(n - 1):
	visited[v] = True
	ps.append(v)
	v = max((to for to in g[v] if not visited[to]), key=seen.__getitem__, default=-1)
	for to in g[v]:
		seen[to] += 1
print(*ps)