f = list(map(int, input().split()))
n = f[0]
f.pop(0)
a = 1
b = 1000
m = [2]
spis = ''
for i in range(3, b, 2):
	x = 0
	for k in range(1, i // 2, 2):
		if i % k == 0 and k != 1 and k != 0:
			x = 1
			break
	if x == 0:
		m.append(i)
for u in range(0, n):
    a = f[u]
    for i in range(100):
        x = a
        b = str(a)
        v = 0
        for j in range(len(b)):
            v += int(b[j])
        d = []
        for k in m:
            while x % k == 0:
                x //= k
                q = str(k)
                for w in range(len(str(k))):
                    d.append(int(q[w]))            
        if sum(d) == v and a not in m:
            spis += str(a)
            break
        a += 1
print(spis)
