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
Tags: Implementation

Constructive algorithms

Starter code:

Solutions:
import os
import sys
from math import *
from collections import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
C = defaultdict(list)
a = []
for i in range(n):
	a.append(value())
	for j in a[-1]:
		C[j].append(i)
for i in C:
	if len(C[i]) == 1:
		last = i
		for k in a[C[i][0]]:
			if len(C[k]) == 2:
				seclast = k
over = set([last, seclast])
ans = [last, seclast]
i = 0
for _ in range(n - 2):
	key = ans[i]
	triplet = C[key][0]
	i += 1
	for k in a[triplet]:
		C[k].remove(triplet)
		if k not in over:
			over.add(k)
			ans.append(k)
print(*ans)


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
import bisect
import heapq
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
n = int(ri())
arr = []
dic = {}
no = -1
dic1 = {}
ind = [-1] * (n + 1)
for i in range(n - 2):
	temp = Ri()
	arr.append(temp)
	for j in temp:
		ind[j] = i
		if j in dic:
			dic[j] += 1
		else:
			dic[j] = 1
	if tuple(sorted((temp[0], temp[1]))) in dic1:
		dic1.get(tuple(sorted((temp[0], temp[1])))).append(temp[2])
	else:
		dic1[tuple(sorted((temp[0], temp[1])))] = [temp[2]]
	if tuple(sorted((temp[2], temp[1]))) in dic1:
		dic1.get(tuple(sorted((temp[2], temp[1])))).append(temp[0])
	else:
		dic1[tuple(sorted((temp[2], temp[1])))] = [temp[0]]
	if tuple(sorted((temp[0], temp[2]))) in dic1:
		dic1.get(tuple(sorted((temp[0], temp[2])))).append(temp[1])
	else:
		dic1[tuple(sorted((temp[0], temp[2])))] = [temp[1]]
for i in dic:
	if dic[i] == 1:
		no = i
		break
ans = []
ans.append(no)
tup = arr[ind[no]]
(x, y) = (-1, -1)
for i in tup:
	if x == -1 and i != no:
		x = i
		continue
	if y == -1 and i != no:
		y = i
(fi, se) = (-1, -1)
if dic[y] == 2:
	ans.append(y)
	fi = y
	se = x
else:
	ans.append(x)
	fi = x
	se = y
ans.append(se)
while len(ans) < n:
	th = dic1[tuple(sorted((ans[-1], ans[-2])))]
	for i in th:
		if i != ans[-3]:
			th = i
			break
	ans.append(th)
print(*ans)


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


def common(l1, l2):
	for i in range(3):
		for j in range(3):
			if l1[i] == l2[j]:
				return l1[i]
	return 0

def comp(l1, a, b):
	for i in l1:
		if i != a and i != b:
			return i
n = int(input())
l = []
d = {}
commons = {}
for i in range(n - 2):
	l.append(list(map(int, input().split())))
for i in range(n - 2):
	for j in l[i]:
		if j in d:
			d[j].append(i)
		else:
			d[j] = [i]
start = -1
end = -1
for i in d:
	if len(d[i]) == 1:
		if start == -1:
			start = i
			startg = d[i][0]
		else:
			end = i
			endg = d[i][0]
			break
for i in l[startg]:
	if len(d[i]) == 2:
		second = i
		break
for i in l[endg]:
	if len(d[i]) == 2:
		seclast = i
		break
i = 1
ans = [-1] * n
ans[0] = start
ans[1] = second
ans[n - 1] = end
ans[n - 2] = seclast
if ans[i - 1] in l[d[ans[i]][0]]:
	ans[i + 1] = comp(l[d[ans[i]][0]], ans[i - 1], ans[i])
elif ans[i - 1] in l[d[ans[i]][1]]:
	ans[i + 1] = comp(l[d[ans[i]][1]], ans[i - 1], ans[i])
else:
	ans[i + 1] = comp(l[d[ans[i]][2]], ans[i - 1], ans[i])
i += 1
while i < n - 3:
	if ans[i - 1] in l[d[ans[i]][0]] and ans[i - 2] not in l[d[ans[i]][0]]:
		ans[i + 1] = comp(l[d[ans[i]][0]], ans[i - 1], ans[i])
	elif ans[i - 1] in l[d[ans[i]][1]] and ans[i - 2] not in l[d[ans[i]][1]]:
		ans[i + 1] = comp(l[d[ans[i]][1]], ans[i - 1], ans[i])
	else:
		ans[i + 1] = comp(l[d[ans[i]][2]], ans[i - 1], ans[i])
	i += 1
print(*ans)


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)


n = int(input())
q = []
n2p = dict()
p2n = []
for i in range(n - 2):
	ns = list(map(int, input().split()))
	for num in ns:
		if num in n2p:
			n2p[num].add(i)
		else:
			n2p[num] = set([i])
	p2n.append(set(ns))
for (k, v) in n2p.items():
	if len(v) == 1:
		num = k
		p = list(v)[0]
		break
result = [num]
for num in p2n[p]:
	if len(n2p[num]) == 2:
		result.append(num)
		break
p = -1
while len(result) < n:
	p = list(n2p[result[-1]] & n2p[result[-2]] - set([p]))[0]
	num = p2n[p] - set(result[-2:])
	result.append(list(num)[0])
print(' '.join(map(str, result)))


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)


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()
		a = []
		z = []
		d = {}
		pos = {}
		for i in range(n - 2):
			k = ria()
			for j in k:
				if j in d:
					d[j] += 1
				else:
					d[j] = 1
				if j in pos:
					pos[j].append(i)
				else:
					pos[j] = [i]
			z += k
			a.append(k)
		ans = []
		hai = {}
		for i in pos:
			if len(pos[i]) == 1:
				ans.append(i)
				hai[i] = 1
				g = pos[i][0]
				break
		for i in range(n - 2 - 2):
			f = a[g]
			b = -1
			c = -1
			for i in f:
				if len(pos[i]) == 2:
					b = i
					ans.append(i)
					hai[i] = 1
				if len(pos[i]) == 3:
					c = i
			if b not in pos or c not in pos:
				break
			pos[b].remove(g)
			pos[c].remove(g)
			g = pos[b][0]
		v = []
		for i in z:
			if i not in hai:
				v.append(i)
		v = set(v)
		for i in v:
			if d[i] == 3:
				a1 = i
			if d[i] == 2:
				a2 = i
			if d[i] == 1:
				a3 = i
		ans += [a1, a2, a3]
		print(*ans)
	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())
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()


n = int(input())
a = {}
b = {}
for _ in range(n - 2):
	(x, y, z) = sorted(map(int, input().split()))
	a[x] = a.get(x, 0) + 1
	a[y] = a.get(y, 0) + 1
	a[z] = a.get(z, 0) + 1
	key = (x, y)
	if key not in b:
		b[key] = [z]
	else:
		b[key] += (z,)
	key = (x, z)
	if key not in b:
		b[key] = [y]
	else:
		b[key] += (y,)
	key = (y, z)
	if key not in b:
		b[key] = [x]
	else:
		b[key] += (x,)
x = [key for (key, val) in a.items() if val == 1][0]
for key in b:
	if x in key and a[sum(key) - x] == 2:
		y = key[0] if x == key[1] else key[1]
		ans = [x, y]
		c = {x: 1, y: 1}
		for _ in range(n - 2):
			key = tuple(sorted((x, y)))
			z = b[key]
			if z[0] in c:
				z = z[1]
			else:
				z = z[0]
			ans += (z,)
			c[z] = 1
			(x, y) = (y, z)
		print(*ans)
		break
else:
	print('Oops!')


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 = {}
used = set()
for itr in range(n - 2):
	(p, q, r) = map(int, input().split())
	if p in d:
		d[p].append([p, q, r])
	else:
		d[p] = [[p, q, r]]
	if q in d:
		d[q].append([p, q, r])
	else:
		d[q] = [[p, q, r]]
	if r in d:
		d[r].append([p, q, r])
	else:
		d[r] = [[p, q, r]]
ans = []
for itr in d:
	if len(d[itr]) == 1:
		k = itr
		break
ans.append(k)
used.add(frozenset(d[k][0]))
for itr in d[k][0]:
	if itr == k:
		continue
	ans.insert(len(d[itr]) - 1, itr)
for itr in range(1, n - 2):
	for tup in d[ans[itr]]:
		if frozenset(tup) in used:
			continue
		for i in tup:
			if i == ans[itr] or i == ans[itr + 1]:
				continue
			ans.append(i)
		used.add(frozenset(tup))
print(*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)


from collections import defaultdict as dd
n = int(input())
l = []
d = dd(list)
d2 = dd(list)
for _ in range(n - 2):
	(a, b, c) = map(int, input().split())
	l += [[a, b, c]]
for i in range(n - 2):
	d[l[i][0]] += [i]
	d[l[i][1]] += [i]
	d[l[i][2]] += [i]
for i in range(n - 2):
	d2[l[i][0], l[i][1]] += [l[i][2]]
	d2[l[i][1], l[i][2]] += [l[i][0]]
	d2[l[i][2], l[i][1]] += [l[i][0]]
	d2[l[i][1], l[i][0]] += [l[i][2]]
	d2[l[i][0], l[i][2]] += [l[i][1]]
	d2[l[i][2], l[i][0]] += [l[i][1]]
for i in d:
	if len(d[i]) == 1:
		k = i
		break
ans = [k]
bef = k
for i in d:
	if len(d[i]) == 2:
		for j in d[i]:
			if j == d[k][0]:
				p = i
				break
ans += [p]
ind = d[k][0]
nex = [ans[0], ans[1]]
bef = 99999999999999
for i in range(n - 2):
	for j in d2[tuple(nex)]:
		if j != bef:
			ans += [j]
	bef = nex.pop(0)
	nex += [ans[-1]]
print(*ans)


def solve(a, b, groups, nums, visited):
	group1 = set(nums[a])
	group2 = set(nums[b])
	common = group1 & group2
	for i in common:
		if i not in visited:
			group = i
	visited.add(group)
	for i in groups[group]:
		if i != a and i != b:
			return i

def main():
	n = int(input())
	nums = {}
	ans = []
	groups = []
	for i in range(n - 2):
		arr = list(map(int, input().split()))
		for j in arr:
			if j not in nums.keys():
				nums[j] = [i]
			else:
				nums[j].append(i)
		groups.append(arr)
	first = -1
	for i in nums.keys():
		if len(nums[i]) == 1:
			first = i
			break
	visited = set()
	ans.append(first)
	group = nums[first][0]
	for i in groups[group]:
		if len(nums[i]) == 2:
			second = i
			break
	ans.append(second)
	for i in groups[group]:
		if i not in ans:
			ans.append(i)
			break
	visited.add(group)
	a = ans[-2]
	b = ans[-1]
	for i in range(n - 3):
		ans.append(solve(a, b, groups, nums, visited))
		a = ans[-2]
		b = ans[-1]
	for i in ans:
		print(i, end=' ')
main()


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = 1
for _ in range(t):
	n = ip()
	arr = []
	for i in range(n - 2):
		arr.append(list(inp()))
	org = [None] * n
	sam = []
	pos = dd(list)
	for i in arr:
		for j in i:
			sam.append(j)
	for i in range(n - 2):
		for j in arr[i]:
			pos[j].append(i)
	dic = Counter(sam)
	val = []
	val2 = []
	for i in dic:
		if dic[i] == 1:
			val.append(i)
		if dic[i] == 2:
			val2.append(i)
	org[0] = val[0]
	flag = True
	for i in pos[org[0]]:
		ch = arr[i]
		if val2[0] in ch:
			org[1] = val2[0]
			flag = False
	if flag:
		org[1] = val2[1]
	c = 2
	mark = [True] * (n + 1)
	while c < n:
		ele1 = org[c - 1]
		ele2 = org[c - 2]
		mark[ele1] = False
		mark[ele2] = False
		p = list(set(pos[ele1]) & set(pos[ele2]))
		for i in p:
			ch = arr[i]
			for j in ch:
				if mark[j]:
					org[c] = j
		c += 1
	print(*org)


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 collections

def repr(a, b):
	return f'{a}_{b}' if a < b else f'{b}_{a}'
l = int(input())
hist = collections.defaultdict(int)
pair_map = collections.defaultdict(list)
used = [False for i in range(l + 1)]
for i in range(l - 2):
	line = input()
	(a, b, c) = [int(i) for i in line.split(' ')]
	hist[a] += 1
	hist[b] += 1
	hist[c] += 1
	pair_map[repr(a, b)].append(c)
	pair_map[repr(a, c)].append(b)
	pair_map[repr(b, c)].append(a)
left = 0
left_next_cands = []
for (k, v) in hist.items():
	if v == 1 and left > 0:
		last = k
	elif v == 1:
		left = k
	if v == 2:
		left_next_cands.append(k)
chain = None
(current, opposite) = (left_next_cands[0], left_next_cands[1]) if repr(left, left_next_cands[0]) in pair_map else (left_next_cands[1], left_next_cands[0])
used[left] = True
used[current] = True
res = [left, current]
for i in range(l - 2):
	chain = repr(left, current)
	cands = pair_map[chain]
	if False and len(cands) == 1:
		n = cands[0]
		res.append(n)
	else:
		n = cands[0] if not used[cands[0]] else cands[1]
		res.append(n)
	used[n] = True
	(left, current) = (current, n)
print(' '.join([str(x) for x in res]))


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)


import sys
from collections import defaultdict
vis = defaultdict(int)
graph = defaultdict(list)
vis = defaultdict(int)
vis1 = defaultdict(int)
count = defaultdict(list)
n = int(sys.stdin.readline())
for _ in range(n - 2):
	(a, b, c) = map(int, sys.stdin.readline().split())
	graph[a].append([a, b, c])
	graph[b].append([a, b, c])
	graph[c].append([a, b, c])
for i in graph:
	if len(graph[i]) == 1 or len(graph[i]) == 2:
		count[len(graph[i])].append(i)
ans = [-1 for _ in range(n)]
ans[0] = count[1][0]
ans[-1] = count[1][-1]
(vis[ans[0]], vis[ans[-1]]) = (1, 1)
for k in graph[ans[0]]:
	for a in k:
		if a in count[2]:
			vis[a] = 1
			break
ans[1] = a
for k in graph[ans[-1]]:
	for a in k:
		if a in count[2]:
			vis[a] = 1
			break
ans[-2] = a
for i in range(2, n):
	for k in graph[ans[i - 2]]:
		for a in k:
			if vis[a] != 1:
				ans[i] = a
				vis[a] = 1
print(*ans)


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


import collections
from collections import defaultdict
import sys
input = sys.stdin.readline
n = int(input())
store = defaultdict(list)
ans = []
visited = [0] * (n + 1)
for i in range(n - 2):
	(u, v, w) = map(int, input().split())
	store[u].append(v)
	store[u].append(w)
	store[v].append(u)
	store[v].append(w)
	store[w].append(v)
	store[w].append(u)
for i in store:
	if len(store[i]) == 2:
		ans.append(i)
		x = store[i][0]
		if len(store[x]) == 4:
			ans.append(store[i][0])
			ans.append(store[i][1])
		else:
			ans.append(store[i][1])
			ans.append(store[i][0])
		(visited[i], visited[store[i][0]], visited[store[i][1]]) = (1, 1, 1)
		break
queue = collections.deque([ans[-1]])
while queue:
	q = queue.popleft()
	for j in store[q]:
		if visited[j] == 0:
			if store[q].count(j) == 2:
				ans.append(j)
				visited[j] = 1
				queue.append(j)
for i in store:
	if visited[i] == 0:
		ans.append(i)
print(*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)


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def solve():
	(n,) = aj()
	G = defaultdict(list)

	def addEdge(a, b):
		G[a].append(b)
		G[b].append(a)
	C = Counter()
	Id = {}
	H = set()
	for i in range(n - 2):
		A = aj()
		A.sort()
		A = tuple(A)
		H.add(A)
		(a, b, c) = A
		if (a, b) in Id:
			addEdge(Id[a, b], A)
			C[A] += 1
		if (b, c) in Id:
			addEdge(Id[b, c], A)
			C[A] += 1
		if (a, c) in Id:
			addEdge(Id[a, c], A)
			C[A] += 1
		Id[a, b] = Id[b, c] = Id[a, c] = A

	def dfs(node):
		Ans = []
		St = deque()
		St.append(node)
		vis = set()
		vis.add(node)
		while St:
			x = St.pop()
			Ans.append(x)
			for i in G.get(x, []):
				if i not in vis:
					vis.add(i)
					St.append(i)
		return Ans
	node = A
	for i in G:
		if len(G[i]) == 1:
			node = i
			break
	series = dfs(node)
	common = set(series[0]).intersection(set(series[1]))
	rem = set(series[0]) - common
	stack = list(rem) + list(common)
	i = 1
	S = set(stack)
	while i < n - 2:
		(x, y, z) = series[i]
		aa = {stack[-3], stack[-2], stack[-1]}
		bb = {x, y, z}
		common = aa.intersection(bb)
		rem = bb - common
		if len(common - {stack[-2], stack[-1]}) != 0:
			(stack[-3], stack[-2]) = (stack[-2], stack[-3])
		for j in rem:
			if j not in S:
				stack.append(j)
				S.add(j)
				break
		i += 1
	a = tuple(sorted([stack[0], stack[1], stack[2]]))
	b = tuple(sorted([stack[-3], stack[-2], stack[-1]]))
	if a not in H:
		stack.append(stack.pop(0))
	elif b not in H:
		stack.insert(0, stack.pop())
	print(*stack)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


import sys
from collections import defaultdict, Counter

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N = INT()
C = Counter()
C2 = defaultdict(list)
for i in range(N - 2):
	q = LIST()
	q.sort()
	(a, b, c) = q
	C[a] += 1
	C[b] += 1
	C[c] += 1
	C2[a].append((b, c))
	C2[b].append((a, c))
	C2[c].append((a, b))
cur = 0
ans = []
used = set()
for (k, v) in C.items():
	if v == 1:
		cur = k
		ans.append(k)
		used.add(k)
		for (a, b) in C2[cur]:
			if C[a] == 2:
				ans.append(a)
				used.add(a)
			else:
				ans.append(b)
				used.add(b)
		break
while len(ans) < N:
	for (a, b) in C2[cur]:
		if a not in used:
			used.add(a)
			ans.append(a)
			cur = b
			break
		elif b not in used:
			used.add(b)
			ans.append(b)
			cur = a
			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]))


n = int(input())
h = {}
for i in range(n - 2):
	(x, y, z) = map(int, input().split())
	if x not in h:
		h[x] = []
	if y not in h:
		h[y] = []
	if z not in h:
		h[z] = []
	h[x].append(y)
	h[x].append(z)
	h[x] = set(h[x])
	h[x] = list(h[x])
	h[y].append(x)
	h[y].append(z)
	h[y] = set(h[y])
	h[y] = list(h[y])
	h[z].append(x)
	h[z].append(y)
	h[z] = set(h[z])
	h[z] = list(h[z])
single = 0
for i in h:
	if len(h[i]) == 2:
		single = i
		break
ans = []
vis = {}
vis[single] = True
ans.append(single)
first = single
if len(h[h[single][0]]) == 3:
	ans.append(h[single][0])
	vis[h[single][0]] = True
	second = h[single][0]
else:
	ans.append(h[single][1])
	vis[h[single][1]] = True
	second = h[single][1]
for i in range(n - 2):
	a = h[first]
	b = h[second]
	a = set(a)
	b = set(b)
	a = a.intersection(b)
	a = list(a)
	for x in a:
		if x not in vis:
			ans.append(x)
			vis[x] = True
			first = second
			second = x
			break
print(' '.join(map(str, ans)))


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)


from sys import stdin

def input():
	return stdin.readline().strip()
from collections import defaultdict
n = int(input())
triplets = defaultdict(defaultdict)
counter = defaultdict(int)
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	counter[a] += 1
	counter[b] += 1
	counter[c] += 1
	triplets[a][a] = 1
	triplets[a][b] = 1
	triplets[a][c] = 1
	triplets[b][a] = 1
	triplets[b][b] = 1
	triplets[b][c] = 1
	triplets[c][a] = 1
	triplets[c][b] = 1
	triplets[c][c] = 1
lst = sorted(counter.items(), key=lambda x: x[1])
(i, j) = (1, n - 1)
place = [0] * n
(a, b) = (lst[0][0], lst[1][1])
(place[0], place[-1]) = (a, b)

def init(x):
	for ele in triplets[x]:
		triplets[ele][x] = 0
	triplets[x][x] = 0
init(a)
for ele in triplets[a]:
	if counter[ele] == 2:
		counter[ele] -= 1
		place[i] = ele
		init(ele)
		i += 1
while i <= j:
	x = place[i - 2]
	for ele in triplets[x]:
		if triplets[x][ele] == 1:
			place[i] = ele
			i += 1
			init(ele)
print(*place)


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, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

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 SieveOfEratosthenes(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

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

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

def li():
	return list(map(int, input().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')

def commonelement(a, b):
	c = 0
	for i in a:
		if i in b:
			c += 1
	return c
t = 1
for _ in range(t):
	n = ii()
	l = []
	d = defaultdict(list)
	for i in range(n - 2):
		x = li()
		d[x[0]].append(i)
		d[x[1]].append(i)
		d[x[2]].append(i)
		l.append(x)
	firstelement = 0
	for i in d.keys():
		if len(d[i]) == 1:
			firstelement = i
	temp = l[d[firstelement][0]][:]
	temp.remove(firstelement)
	other1 = temp[0]
	other2 = temp[1]
	if len(d[other1]) > len(d[other2]):
		(other1, other2) = (other2, other1)
	ans = [firstelement, other1, other2]
	prev = d[firstelement][0]
	while len(ans) < n:
		x = d[other2]
		x.remove(prev)
		if len(x) == 1:
			xx = l[x[0]][:]
			xx.remove(ans[-1])
			xx.remove(ans[-2])
			ans.append(xx[0])
			continue
		temp1 = l[x[0]][:]
		temp2 = l[x[1]][:]
		c1 = commonelement(temp1, l[prev])
		c2 = commonelement(temp2, l[prev])
		if c1 > c2:
			temp1.remove(ans[-1])
			temp1.remove(ans[-2])
			ans.append(temp1[0])
			other2 = temp1[0]
			prev = x[0]
		else:
			temp2.remove(ans[-1])
			temp2.remove(ans[-2])
			ans.append(temp2[0])
			other2 = temp2[0]
			prev = x[1]
	print(*ans)


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)


from collections import defaultdict

class Input:

	def __init__(self):
		from sys import stdin
		lines = stdin.readlines()
		self.lines = list([line.rstrip('\n') for line in reversed(lines) if line != '\n'])

	def input(self):
		return self.lines.pop()

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

	def __bool__(self):
		return bool(self.lines)

def build_hash(triplets):
	q_map = defaultdict(list)
	for triplet in triplets:
		for q in triplet:
			q_map[q].append(tuple(triplet))
	return q_map

def find_one_end(q_map):
	for (q, triplets) in q_map.items():
		if len(triplets) == 1:
			return (q, triplets[0])

def find_second(first_value, q_map):
	for (q, triplets) in q_map.items():
		if len(triplets) == 2:
			for triplet in triplets:
				if first_value in triplet:
					return (q, triplet)

def remove(q_map, triplet):
	q_map[triplet[0]].remove(triplet)
	q_map[triplet[1]].remove(triplet)
	q_map[triplet[2]].remove(triplet)

def fill_next(ps, q_map):
	left = set(q_map[ps[-1]])
	right = set(q_map[ps[-2]])
	triplets = list(left.intersection(right))
	triplet = triplets[0]
	value = [i for i in triplet if i not in ps[-2:]][0]
	ps.append(value)
	remove(q_map, triplet)

def construct(q_map, n):
	(first, first_triplet) = find_one_end(q_map)
	(second, second_triplet) = find_second(first, q_map)
	ps = [first, second]
	while len(ps) < n:
		fill_next(ps, q_map)
	return ps
inp = Input()
n = int(inp.input())
triplets = []
for i in range(n - 2):
	triplets.append(inp.input_int_list())
ps = construct(build_hash(triplets), n)
print(' '.join(map(str, ps)))


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


n = int(input().strip())
g = {}
rg = {}
cnt = {}
for i in range(1, n + 1):
	cnt[str(i)] = 0
	rg[str(i)] = []
for _ in range(n - 2):
	arr = [x for x in input().split()]
	arr.sort()
	(a, b, c) = arr
	for e in arr:
		cnt[e] += 1
	for (p, tr) in [((a, b), c), ((a, c), b), ((b, c), a)]:
		if p not in g:
			g[p] = []
		rg[tr].append(p)
		g[p].append(tr)
cur = None
for k in cnt:
	if cnt[k] == 1:
		cur = k
was = set()
was.add(cur)
res = [cur]
(ca, cb) = rg[cur][0]
if cnt[ca] == 2:
	cur = ca
else:
	cur = cb
was.add(cur)
res.append(cur)
while len(res) != n:
	cur = [res[-1], res[-2]]
	cur.sort()
	cur = tuple(cur)
	for to in g[cur]:
		if to in was:
			continue
		res.append(to)
		was.add(to)
print(' '.join(res))


n = int(input())
table = {}
for _ in range(n - 2):
	(a, b, c) = map(int, input().split())
	if a in table.keys():
		if b in table[a].keys():
			table[a][b] += 1
		else:
			table[a][b] = 1
		if c in table[a].keys():
			table[a][c] += 1
		else:
			table[a][c] = 1
	else:
		table[a] = {b: 1, c: 1}
	if b in table.keys():
		if a in table[b].keys():
			table[b][a] += 1
		else:
			table[b][a] = 1
		if c in table[b].keys():
			table[b][c] += 1
		else:
			table[b][c] = 1
	else:
		table[b] = {a: 1, c: 1}
	if c in table.keys():
		if b in table[c].keys():
			table[c][b] += 1
		else:
			table[c][b] = 1
		if a in table[c].keys():
			table[c][a] += 1
		else:
			table[c][a] = 1
	else:
		table[c] = {a: 1, b: 1}
processed = [int(0) for u in range(n + 1)]
final_solution = [int(0) for _ in range(200000 + 1)]
exceptions_2 = []
exceptions_3 = []
solutions = []
for item in table.keys():
	if len(table[item]) == 4:
		final_solution[100000] = item
		for tt in table[item]:
			if table[item][tt] == 2:
				solutions.append(tt)
		if len(solutions) > 0:
			break
final_solution[100000 - 1] = solutions[0]
final_solution[100000 + 1] = solutions[1]
processed[final_solution[100000]] = 1
processed[final_solution[100000 - 1]] = 1
processed[final_solution[100000 + 1]] = 1
for i in range(100000 - 1, 0, -1):
	pp = False
	if len(table[final_solution[i]]) == 4:
		for tt in table[final_solution[i]]:
			if table[final_solution[i]][tt] == 2 and processed[tt] == 0:
				final_solution[i - 1] = tt
				processed[tt] = 1
				pp = True
		if pp == False:
			break
	else:
		break
for i in range(100000 + 1, 200000, +1):
	pp = False
	if len(table[final_solution[i]]) == 4:
		for tt in table[final_solution[i]]:
			if table[final_solution[i]][tt] == 2 and processed[tt] == 0:
				final_solution[i + 1] = tt
				processed[tt] = 1
				pp = True
		if pp == False:
			break
	else:
		break
start = -1
end = -1
for i in range(0, 200000 + 1):
	if final_solution[i] != 0:
		start = i
		break
for i in range(start, 200000, 1):
	if final_solution[i] == 0:
		end = i - 1
		break
end += 1
for item in table[final_solution[start]]:
	if processed[item] == 0:
		start -= 1
		final_solution[start] = item
		processed[item] = 1
for item in table[final_solution[end - 1]]:
	if processed[item] == 0:
		final_solution[end] = item
		processed[item] = 1
for i in range(start, end + 1, 1):
	print(final_solution[i], end=' ')


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


import sys, math
MOD = 10 ** 9 + 7
n = int(input())
t = [0 for i in range(n + 1)]
f = {1: set(), 2: set(), 3: set()}
adj = [[] for i in range(n + 1)]
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	t[a] += 1
	t[b] += 1
	t[c] += 1
	adj[a].append((b, c))
	adj[b].append((c, a))
	adj[c].append((a, b))
for i in range(1, n + 1):
	f[t[i]].add(i)
ans = [f[1].pop()]
for i in range(n - 4):
	p = ans[-1]
	(pa, pb) = adj[p][-1]
	adj[p].pop()
	(t1, t2) = ((p, pa), (pa, p))
	(t3, t4) = ((p, pb), (pb, p))
	if pa in f[2]:
		f[2].remove(pa)
		f[3].remove(pb)
		f[2].add(pb)
		ans.append(pa)
	else:
		f[2].remove(pb)
		f[3].remove(pa)
		f[2].add(pa)
		ans.append(pb)
	if i == n - 5:
		continue
	if t1 in adj[pb]:
		adj[pb].remove(t1)
	if t2 in adj[pb]:
		adj[pb].remove(t2)
	if t3 in adj[pa]:
		adj[pa].remove(t3)
	if t4 in adj[pa]:
		adj[pa].remove(t4)
(x1, x2) = tuple(f[2])
z = f[1].pop()
if (ans[-2], x1) not in adj[ans[-1]] and (x1, ans[-2]) not in adj[ans[-2]]:
	(x1, x2) = (x2, x1)
ans.append(x1)
ans.append(x2)
ans.append(z)
print(*ans)


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


a = int(input())
A = []
for i in range(a):
	A.append(set())
for i in range(a - 2):
	(x, y, z) = map(int, input().split())
	x -= 1
	y -= 1
	z -= 1
	A[x].add(y)
	A[x].add(z)
	A[y].add(x)
	A[y].add(z)
	A[z].add(x)
	A[z].add(y)
for i in range(len(A)):
	if len(A[i]) == 2:
		k = i
m2 = k
B = [k + 1]
Z = list(A[k])
if len(A[Z[0]]) == 3:
	B.append(Z[0] + 1)
	m1 = Z[0]
else:
	B.append(Z[1] + 1)
	m1 = Z[1]
for i in range(a - 2):
	w = list(A[m1] & A[m2])
	if len(B) > 2:
		if w[0] + 1 != B[-3]:
			B.append(w[0] + 1)
			m2 = int(m1)
			m1 = w[0]
		else:
			B.append(w[1] + 1)
			m2 = int(m1)
			m1 = w[1]
	else:
		B.append(w[0] + 1)
		m2 = int(m1)
		m1 = w[0]
print(*B)


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())
l = []
d = {}
count = {}
for i in range(n - 2):
	l.append(list(map(int, input().split())))
	temp = l[-1]
	if temp[0] in count:
		count[temp[0]][0] += 1
	else:
		count[temp[0]] = [1, temp]
	if temp[1] in count:
		count[temp[1]][0] += 1
	else:
		count[temp[1]] = [1, temp]
	if temp[2] in count:
		count[temp[2]][0] += 1
	else:
		count[temp[2]] = [1, temp]
	if (temp[0], temp[1]) in d:
		d[temp[0], temp[1]].append(temp[2])
	else:
		d[temp[0], temp[1]] = [temp[2]]
	if (temp[1], temp[0]) in d:
		d[temp[1], temp[0]].append(temp[2])
	else:
		d[temp[1], temp[0]] = [temp[2]]
	if (temp[0], temp[2]) in d:
		d[temp[0], temp[2]].append(temp[1])
	else:
		d[temp[0], temp[2]] = [temp[1]]
	if (temp[2], temp[1]) in d:
		d[temp[2], temp[1]].append(temp[0])
	else:
		d[temp[2], temp[1]] = [temp[0]]
	if (temp[2], temp[0]) in d:
		d[temp[2], temp[0]].append(temp[1])
	else:
		d[temp[2], temp[0]] = [temp[1]]
	if (temp[1], temp[2]) in d:
		d[temp[1], temp[2]].append(temp[0])
	else:
		d[temp[1], temp[2]] = [temp[0]]
start = -1
second = -1
for i in count:
	if count[i][0] == 1:
		if start == -1:
			start = count[i][1]
			sn = i
		else:
			end = count[i][1]
			en = i
			break
	elif count[i][0] == 2:
		if second == -1:
			second = count[i][1]
			secn = i
		else:
			second2 = count[i][1]
			secn2 = i
ans = []
ans.append(sn)
print(sn, end=' ')
if (sn, secn) in d:
	thirdn = d[sn, secn][0]
	print(secn, thirdn, end=' ')
	ans.append(secn)
else:
	thirdn = d[sn, secn2][0]
	print(secn2, thirdn, end=' ')
	ans.append(secn2)
ans.append(thirdn)
for i in range(n - 3):
	temp = d[ans[-2], ans[-1]]
	if temp[0] != ans[-3]:
		ans.append(temp[0])
		print(temp[0], end=' ')
	else:
		ans.append(temp[1])
		print(temp[1], end=' ')


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


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)

def return_nxt(i, a, b):
	visited.add(i)
	c = (set(mem2[i]) - set([a, b])).pop()
	final.append(c)
	if len(final) == n:
		return (-1, b, c)
	new_idx = (set(mem1[b]) - visited & set(mem1[c]) - visited).pop()
	return (new_idx, b, c)
import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input().split()))
from collections import defaultdict
mem1 = defaultdict(list)
mem2 = defaultdict(list)
(n,) = I()
for t1 in range(n - 2):
	(a, b, c) = I()
	mem2[t1] = [a, b, c]
	mem1[a].append(t1)
	mem1[b].append(t1)
	mem1[c].append(t1)
start1 = -1
start2 = -1
start_idx = -1
for i in mem1:
	if len(mem1[i]) == 1:
		start1 = i
		idx = mem1[i][0]
		start_idx = mem1[i][0]
		for j in range(len(mem2[idx])):
			val = mem2[idx][j]
			if len(mem1[val]) == 2:
				start2 = val
				break
		break
final = [start1, start2]
visited = set()
for i in range(n - 2):
	(start_idx, start1, start2) = return_nxt(start_idx, start1, start2)
print(*final)


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


n = int(input())
triple = [set(map(int, input().split())) for i in range(n - 2)]
nb = [set() for i in range(n + 1)]
sharing = [[] for i in range(n + 1)]
for i in range(n - 2):
	for elt in triple[i]:
		sharing[elt].append(i)
for i in range(1, n + 1):
	for a in sharing[i]:
		for b in sharing[i]:
			if len(triple[a].intersection(triple[b])) == 2:
				nb[a].add(b)
for i in range(n + 1):
	if len(nb[i]) == 1:
		break
order = [i]
cur = i
prev = -1
while True:
	if prev != -1 and len(nb[cur]) == 1:
		break
	for elt in nb[cur]:
		if elt != prev:
			prev = cur
			cur = elt
			order.append(cur)
			break
odp = [-1] * n
for i in range(n - 3):
	l = triple[order[i]].intersection(triple[order[i + 1]])
	for elt in triple[order[i]]:
		if elt not in l:
			odp[i] = elt
	for elt in triple[order[i + 1]]:
		if elt not in l:
			odp[i + 3] = elt
if n == 5:
	for i in range(1, n + 1):
		if i not in odp:
			odp[2] = i
print(*odp)


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


from collections import defaultdict
import sys
n = int(sys.stdin.readline())
the_frequency_of_numbers = defaultdict(int)
all_qs = defaultdict(list)
for _ in range(n - 2):
	q = [i for i in sys.stdin.readline().split()]
	for num in q:
		the_frequency_of_numbers[num] += 1
		all_qs[num].append(q)
start = min(the_frequency_of_numbers, key=lambda key: the_frequency_of_numbers[key])
triple = all_qs[start][0]
triple.sort(key=lambda key: the_frequency_of_numbers[key])
the_frequency_of_numbers[start] = 10 ** 5 + 1
perm = triple
for ___ in range(n - 4):
	first_element = perm[-3]
	second_element = perm[-2]
	third_element = perm[-1]
	for q_i in all_qs[third_element]:
		if first_element not in q_i and second_element in q_i:
			break
	del q_i[q_i.index(second_element)]
	del q_i[q_i.index(third_element)]
	perm.append(q_i[0])
end = min(the_frequency_of_numbers, key=lambda key: the_frequency_of_numbers[key])
perm.append(end)
print(*perm)


import sys
import math
from collections import defaultdict, Counter, deque
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')
t = int(input())
d = [0] * (t + 1)
l = defaultdict(list)
for i in range(t - 2):
	q = list(map(int, input().split()))
	q.sort()
	d[q[0]] += 1
	d[q[1]] += 1
	d[q[2]] += 1
	l[q[0], q[1]].append(q[2])
	l[q[1], q[2]].append(q[0])
	l[q[0], q[2]].append(q[1])
	l[q[1], q[0]].append(q[2])
	l[q[2], q[1]].append(q[0])
	l[q[2], q[0]].append(q[1])
start1 = []
for j in range(1, t + 1):
	if d[j] == 1:
		start = j
	elif d[j] == 2:
		start1.append(j)
d = [0] * (t + 1)
d[start] = 1
ans = [start]
if l.get((start, start1[0])) != None:
	ans.append(start1[0])
	d[start1[0]] = 1
else:
	ans.append(start1[1])
	d[start1[1]] = 1
for j in range(t - 2):
	for k in l[ans[-1], ans[-2]]:
		if d[k] == 0:
			d[k] = 1
			ans.append(k)
print(*ans)


n = int(input())
arr = [list(map(int, input().split())) for _ in range(n - 2)]
pos = [[] for _ in range(n + 1)]
cnt = [0] * (n + 1)
for i in range(n - 2):
	(a, b, c) = arr[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) = arr[pos[ans[-1]][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 _ in range(n - 3):
	for i in pos[ans[-2]]:
		(a, b, c) = arr[i]
		if ans[-1] in [a, b, c] and ans[-3] not in [a, b, c]:
			tmp = [a, b, c]
			tmp.remove(ans[-2])
			tmp.remove(ans[-1])
			ans.append(tmp[0])
			break
print(*ans)


from collections import defaultdict
n = int(input())
tab = [0] * n
d = defaultdict(list)
cnt = [0] * (n + 1)
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	d[a] += [b, c]
	d[b] += [a, c]
	d[c] += [a, b]
	cnt[a] += 1
	cnt[b] += 1
	cnt[c] += 1
first = cnt.index(1)
last = cnt[first + 1:].index(1)
tab[0] = first
tab[n - 1] = last + first + 1
(x, y) = (d[first][0], d[first][1])
if len(d[x]) < len(d[y]):
	tab[1] = x
	tab[2] = y
else:
	tab[1] = y
	tab[2] = x
i = 3
while i < n - 1:
	curr = 0
	for k in set(d[tab[i - 1]]):
		if d[tab[i - 1]].count(k) == 2 and tab[i - 2] != k:
			curr = k
			break
	tab[i] = curr
	i += 1
print(*tab)


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())
Q = [0] * n
ile = [0] * (n + 1)
co = {}
for j in range(0, n - 2):
	Q[j] = input().split()
	for i in range(0, 3):
		Q[j][i] = int(Q[j][i])
	for i in range(0, 3):
		ile[Q[j][i]] += 1
		c = (Q[j][i - 1], Q[j][(i + 1) % 3])
		d = (c[1], c[0])
		if c in co:
			co[c].append(Q[j][i])
			co[d].append(Q[j][i])
		else:
			co[c] = [Q[j][i]]
			co[d] = [Q[j][i]]
ans = [0] * n
used = {}
krab = 0
for i in range(0, n - 2):
	for j in range(0, 3):
		if ile[Q[i][j]] == 1:
			ans[0] = Q[i][j]
			ans[1] = Q[i][j - 1]
			ans[2] = Q[i][(j + 1) % 3]
for i in range(0, 3):
	used[ans[i]] = 1
ok = 1
for i in range(3, n):
	if ((ans[i - 1], ans[i - 2]) in co) == False:
		ok = 0
		break
	for c in co[ans[i - 1], ans[i - 2]]:
		if (c in used) == False and (i == n - 1 or ile[c] > 1):
			used[c] = 1
			ans[i] = c
			break
	if ans[i] == 0:
		ok = 0
if ok == 1:
	for a in ans:
		print(a, end=' ')
	exit(0)
used = {}
for i in range(0, 3):
	used[ans[i]] = 1
ans[1] ^= ans[2]
ans[2] ^= ans[1]
ans[1] ^= ans[2]
for i in range(3, n):
	for c in co[ans[i - 1], ans[i - 2]]:
		if (c in used) == False and (i == n - 1 or ile[c] > 1):
			used[c] = 1
			ans[i] = c
			break
for a in ans:
	print(a, end=' ')


n = int(input())
l = [[] for i in range(n + 1)]
ct = [0 for i in range(n + 1)]
visited = [False for i in range(n + 1)]
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	l[a].append(b)
	l[a].append(c)
	l[b].append(a)
	l[b].append(c)
	l[c].append(b)
	l[c].append(a)
	ct[a] += 1
	ct[b] += 1
	ct[c] += 1
for i in range(1, n + 1):
	if ct[i] == 1:
		x = i
for i in l[x]:
	if ct[i] == 2:
		y = i
ans = [x, y]
visited[x] = True
visited[y] = True
for i in range(1, n - 1):
	for j in l[x]:
		if visited[j] == 0:
			visited[j] = 1
			ans.append(j)
			x = y
			y = j
			break
print(*ans)


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 sys import stdin, stdout
from collections import Counter
import math
import collections

def rsingle_int():
	return int(stdin.readline().rstrip())

def rmult_int():
	return [int(x) for x in stdin.readline().rstrip().split()]

def rmult_str():
	return stdin.readline().rstrip().split()

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

def rsingle_char():
	return stdin.read(1)

def sortFirst(val):
	return val[0]

def paint(pic, x, y):
	pass

def main():
	n = rsingle_int()
	triples = []
	for _ in range(n):
		triples.append(rmult_int())
	cnts = collections.defaultdict(list)
	for triple in triples:
		for dig in triple:
			cnts[dig].append(triple)
	start = None
	for dig in cnts.keys():
		if len(cnts[dig]) == 1:
			start = dig
			break
	first_t = cnts[start][0]
	first_t.sort(key=lambda dig: len(cnts[dig]))
	p = first_t
	for i in range(2, n - 1):
		trips = cnts[p[i]]
		cand = trips[0]
		for trip in trips:
			if p[i - 1] in trip and p[i - 2] not in trip:
				cand = trip
		next_dig = None
		for dig in cand:
			if dig != p[i] and dig != p[i - 1]:
				next_dig = dig
		p.append(next_dig)
	print(*p)
main()


t = 1
for i in range(t):
	n = int(input())
	l = []
	kdi = dict()
	for numbq in range(n - 2):
		l1 = list(map(int, input().split(' ')))
		l.append(l1)
		for d in l1:
			if d in kdi:
				kdi[d].append(numbq)
			else:
				kdi[d] = [numbq]
	first = 0
	breaker = 0
	flag = 0
	for nm in kdi.keys():
		if len(kdi[nm]) == 1 and flag == 0:
			first = nm
			flag = 1
		elif len(kdi[nm]) == 1:
			breaker = nm
	cur = first
	last_n = kdi[first][0]
	ans = [l[last_n]]
	fin = [first]
	ot = []
	for val in ans[-1]:
		if val != cur:
			ot.append(val)
	oneql = kdi[ot[0]]
	twoql = kdi[ot[1]]
	for z in oneql:
		if z in twoql and z != last_n:
			ans.append(l[z])
			last_n = z
			break
	while True:
		threeql = []
		lol = -1
		for val in ans[-1]:
			if val != ot[0] and val != ot[1]:
				threeql = kdi[val]
				lol = val
		if lol == breaker:
			break
		for z in threeql:
			if z in twoql and z != last_n:
				ans.append(l[z])
				cur = ot[0]
				fin.append(cur)
				oneql = twoql
				twoql = threeql
				last_n = z
				ot = [ot[1], lol]
				break
			if z in oneql and z != last_n:
				ans.append(l[z])
				cur = ot[1]
				fin.append(cur)
				twoql = threeql
				last_n = z
				ot = [ot[0], lol]
				break
	for i in range(len(fin)):
		print(fin[i], end=' ')
	for val in ans[-1]:
		if val in ans[-2] and val in ans[-3]:
			print(val, end=' ')
	for val in ans[-1]:
		if val in ans[-2] and val not in ans[-3]:
			print(val, end=' ')
	print(breaker, end=' ')


from sys import stdin
n = int(stdin.readline().strip())
s = [list(map(int, stdin.readline().strip().split())) for i in range(n - 2)]
cnt = [0 for i in range(n + 1)]
vis = [False for i in range(n + 1)]
st = [set() for i in range(n + 1)]
dic = [dict() for i in range(n + 1)]
for i in s:
	for j in i:
		cnt[j] += 1
x = -1
for i in s:
	for j in i:
		if cnt[j] == 1:
			x = j
		for k in i:
			if k != j:
				st[j].add(tuple([cnt[k], k]))
				if k in dic[j]:
					dic[j][k] += 1
				else:
					dic[j][k] = 1
for i in range(1, n + 1):
	st[i] = list(st[i])
	st[i].sort()
ans = [0 for i in range(n)]
ans[0] = x
mid = n // 2
nex = 2
las = x
vis[x] = True
for i in range(1, 2):
	for j in st[las]:
		if j[0] == nex:
			las = j[1]
			nex += 1
			break
	vis[las] = True
	ans[i] = las
for i in range(2, n):
	mx = 0
	aux = -1
	for j in dic[las]:
		if not vis[j] and dic[las][j] > mx:
			mx = dic[las][j]
			aux = j
	las = aux
	ans[i] = las
	vis[las] = True
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())
arr = []
d = {}
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	arr.append([a, b, c])
	d[a] = d.get(a, []) + [i]
	d[b] = d.get(b, []) + [i]
	d[c] = d.get(c, []) + [i]
for i in d:
	if len(d[i]) == 1:
		ind = d[i][0]
vis = [0] * (n - 2)
visno = [0] * (n + 1)
q = [arr[ind]]
vis[ind] = 1
if len(d[q[0][0]]) == 1:
	print(q[0][0], end=' ')
	visno[q[0][0]] = 1
elif len(d[q[0][1]]) == 1:
	print(q[0][1], end=' ')
	visno[q[0][1]] = 1
else:
	print(q[0][2], end=' ')
	visno[q[0][2]] = 1
if len(d[q[0][0]]) == 2:
	print(q[0][0], end=' ')
	visno[q[0][0]] = 1
	prev = q[0][0]
	if len(d[q[0][0]]) == 2:
		for i in d[q[0][0]]:
			if vis[i] == 0:
				q.append(arr[i])
				vis[i] = 1
elif len(d[q[0][1]]) == 2:
	print(q[0][1], end=' ')
	visno[q[0][1]] = 1
	prev = q[0][1]
	if len(d[q[0][1]]) == 2:
		for i in d[q[0][1]]:
			if vis[i] == 0:
				q.append(arr[i])
				vis[i] = 1
else:
	print(q[0][2], end=' ')
	visno[q[0][2]] = 1
	prev = q[0][2]
	if len(d[q[0][2]]) == 2:
		for i in d[q[0][2]]:
			if vis[i] == 0:
				q.append(arr[i])
				vis[i] = 1
for i in range(n - 4):
	p = q.pop(0)
	for j in p:
		if visno[j] == 0:
			visno[j] = 1
			for k in d[j]:
				if vis[k] == 0:
					vis[k] = 1
					q.append(arr[k])
					print(j, end=' ')
					break
			break
q.pop(0)
for j in q[0]:
	if len(d[j]) == 2:
		print(j, end=' ')
for j in q[0]:
	if len(d[j]) == 1:
		print(j, end=' ')


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


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())
dict0 = {}
dict1 = {}
dict2 = {}
set3 = set([])
for j in range(n - 2):
	(a, b, c) = map(int, input().split())
	setty = set([a, b, c])
	if not a in dict0:
		dict0[a] = 1
		dict1[a] = setty
		dict2[a] = setty
	else:
		dict0[a] += 1
		dict2[a] = dict2[a].union(setty)
	if not b in dict0:
		dict0[b] = 1
		dict1[b] = setty
		dict2[b] = setty
	else:
		dict0[b] += 1
		dict2[b] = dict2[b].union(setty)
	if not c in dict0:
		dict0[c] = 1
		dict1[c] = setty
		dict2[c] = setty
	else:
		dict0[c] += 1
		dict2[c] = dict2[c].union(setty)
	if dict0[a] == 3:
		set3.add(a)
	if dict0[b] == 3:
		set3.add(b)
	if dict0[c] == 3:
		set3.add(c)
ind = 0
for s in dict0.keys():
	if dict0[s] == 1:
		ind = s
		break
ans = [ind]
val = dict1[ind].union(set([]))
val.remove(ind)
for s in val:
	if s in set3:
		continue
	else:
		ans.append(s)
val.remove(ans[-1])
for s in val:
	ans.append(s)
key = ans[-2]
for b in range(n - 3):
	if key in dict2:
		temp = dict2[key].union(set([]))
		if len(temp) == 4:
			for k in range(1, 4):
				if ans[-k] in temp:
					temp.remove(ans[-k])
		elif len(temp) == 5:
			for k in range(1, 5):
				if ans[-k] in temp:
					temp.remove(ans[-k])
		for s in temp:
			ans.append(s)
		key = ans[-2]
print(*ans)


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)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
la = []
hash = defaultdict(int)
hash1 = defaultdict(int)
new_hash = defaultdict(list)
seti = set()
for i in range(n - 2):
	(a, b, c) = map(int, input().split())
	(a, b, c) = sorted([a, b, c])
	hash[a, b] += 1
	hash[b, c] += 1
	hash[a, c] += 1
	hash1[a] += 1
	hash1[b] += 1
	hash1[c] += 1
	seti.add((a, b, c))
st = -1
end = -1
for i in hash:
	(a, b) = i
	if hash1[a] == 1:
		if st == -1:
			st = a
		else:
			end = a
	if hash1[b] == 1:
		if st == -1:
			st = b
		else:
			end = b
	if hash[i] == 2:
		new_hash[a].append(b)
		new_hash[b].append(a)
graph = defaultdict(set)
for i in new_hash:
	if len(new_hash[i]) == 1:
		(a1, b1, c1) = sorted([i, new_hash[i][0], st])
		(a2, b2, c2) = sorted([i, new_hash[i][0], end])
		if (a1, b1, c1) in seti:
			graph[st].add(i)
			graph[i].add(i)
		if (a2, b2, c2) in seti:
			graph[end].add(i)
			graph[i].add(end)
	elif len(new_hash[i]) == 2:
		graph[i].add(new_hash[i][0])
		graph[i].add(new_hash[i][1])
		graph[new_hash[i][0]].add(i)
		graph[new_hash[i][1]].add(i)
ans = []
boo = [False] * (n + 1)

def dfs(n):
	queue = [n]
	boo[n] = True
	while queue:
		z = queue.pop(0)
		ans.append(z)
		for i in graph[z]:
			if not boo[i]:
				boo[i] = True
				queue.append(i)
dfs(st)
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)


n = int(input())
q = [list(map(int, input().split())) for i in range(n - 2)]
was = [[] for i in range(n)]
for i in range(n - 2):
	elem = q[i]
	was[elem[0] - 1] += [i]
	was[elem[1] - 1] += [i]
	was[elem[2] - 1] += [i]
oneUse = -1
doubleUse = -1
for i in range(n):
	if len(was[i]) == 1 and oneUse == -1 and (doubleUse == -1 or was[i][0] in was[doubleUse]):
		oneUse = i
	if len(was[i]) == 2 and doubleUse == -1 and (oneUse == -1 or was[oneUse][0] in was[i]):
		doubleUse = i
print(oneUse + 1, doubleUse + 1, end=' ')
zero = -2
first = oneUse
second = doubleUse
for i in range(n - 2):
	for elem in was[second]:
		if len(q[elem]) == 3 and first + 1 in q[elem] and (zero + 1 not in q[elem]):
			third = sum(q[elem]) - first - second - 3
			break
	print(third + 1, end=' ')
	(zero, first, second) = (first, second, third)


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)