Chef likes to play with big numbers. Today, he has a big positive integer N. He can select any two digits from this number (the digits can be same but their positions should be different) and orders them in any one of the two possible ways. For each of these ways, he creates a two digit number from it (might contain leading zeros). Then, he will pick a character corresponding to the ASCII value equal to this number, i.e. the number 65 corresponds to 'A', 66 to 'B' and so on till 90 for 'Z'. Chef is only interested in finding which of the characters in the range 'A' to 'Z' can possibly be picked this way. 

-----Input-----
The first line of the input contains an integer T denoting the number of test cases.
The first line of the input contains an integer N. 

-----Output-----
For each test case, output a string containing characters Chef can pick in sorted order If the resulting size of string is zero, you should output a new line.

-----Constraints-----
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 10100000

-----Subtasks-----
- Subtask #1 (40 points) N ≤ 1010
- Subtask #2 (60 points) Original Constraints

-----Example-----
Input:
4
65
566
11
1623455078

Output:
A
AB

ACDFGHIJKLNPQRSTUVW

-----Explanation-----
Example case 1. Chef can pick digits 6 and 5 and create integers 56 and 65. The integer 65 corresponds to 'A'.
Example case 2. Chef can pick digits 6 and 5 and create 'A' as it equals 65. He can pick 6 and 6 (they are picked from position 2 and position 3, respectively) to create 'B' too. Hence answer is "AB".
Example case 3. It's not possible to create any character from 'A' to 'Z'. Hence, we just print a new line.

Source: codechef | Difficulty: MEDIUM
Tags: String algorithms

Data structures

Constructive algorithms


Solutions:
al = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
t = input()
for c in range(0, int(t)):
	num = int(input())
	lst = [int(x) for x in str(num)]
	for i in al:
		n = ord(i)
		t1 = n % 10
		t2 = n // 10
		c1 = lst.count(t1)
		c2 = lst.count(t2)
		if t1 == t2:
			if c1 >= 2:
				print(i, end='')
		elif c1 > 0 and c2 > 0:
			print(i, end='')
	print()


t = int(input())
for p in range(t):
	n = str(input())
	l = len(n)
	cnt = [0] * 10
	for i in range(l):
		if cnt[int(n[i])] < 2:
			cnt[int(n[i])] += 1
	output = []
	if cnt[6] > 0:
		for j in range(5, 10):
			if cnt[j] > 0 and j != 6:
				output.append(chr(6 * 10 + j))
			elif j == 6 and cnt[j] > 1:
				output.append(chr(66))
	if cnt[7] > 0:
		for j in range(0, 10):
			if cnt[j] > 0 and j != 7:
				output.append(chr(7 * 10 + j))
			elif j == 7 and cnt[j] > 1:
				output.append(chr(77))
	if cnt[8] > 0:
		for j in range(0, 10):
			if cnt[j] > 0 and j != 8:
				output.append(chr(8 * 10 + j))
			elif j == 8 and cnt[j] > 1:
				output.append(chr(88))
	if cnt[9] > 0:
		if cnt[0] > 0:
			output.append(chr(90))
	ops = ''.join(output)
	if len(ops) != 0:
		print(ops)
	else:
		print()


from itertools import permutations
for j in range(int(input())):
	n = input()
	c = ''
	x = list(permutations(n, 2))
	a = set(x)
	for i in a:
		z = i[0] + i[1]
		if int(z) >= 65 and int(z) <= 90:
			c += chr(int(z))
	if c == '':
		print('')
	else:
		am = list(c)
		am.sort()
		bm = ''.join(am)
		print(bm)


from collections import Counter
t = int(input())
for i in range(t):
	s = input()
	c = Counter(s)
	l = []
	for item in c.keys():
		if c[item] >= 2:
			l.append(item)
			l.append(item)
		else:
			l.append(item)
	l = [int(k) for k in l]
	ans = ''
	for j in range(len(l)):
		for k in range(j + 1, len(l)):
			a = 10 * l[j] + l[k]
			b = 10 * l[k] + l[j]
			if a >= 65 and a <= 90:
				ans += str(chr(a))
			if b >= 65 and b <= 90:
				ans += str(chr(b))
	c = Counter(ans)
	l = list(c.keys())
	l.sort()
	ans = ''
	for item in l:
		ans += item
	print(ans)


t = int(input())
for i in range(t):
	m = input()
	s = set(m)
	an = ''
	for i in range(65, 91):
		if i % 10 == i // 10:
			if m.count(str(i % 10)) >= 2:
				an += chr(i)
		elif str(i % 10) in s and str(i // 10) in s:
			an += chr(i)
	print(an)


for _ in range(int(input())):
	s = input()
	a = [0 for x in range(10)]
	for i in s:
		a[ord(i) - ord('0')] += 1
	ans = ''
	if a[6] != 0:
		i = 6
		a[i] -= 1
		for j in range(5, 10):
			if a[j] != 0:
				ans += chr(60 + j)
		a[i] += 1
	for i in range(7, 9):
		if a[i] != 0:
			a[i] -= 1
			for j in range(10):
				if a[j] != 0:
					ans += chr(i * 10 + j)
			a[i] += 1
	if a[9] != 0 and a[0] != 0:
		ans += 'Z'
	print(ans)


for t in range(int(input())):
	word = input()
	lis = list(word)
	d = {}
	for l in range(10):
		d[l] = None
	s = ''
	for w in lis:
		if d[int(w)] != None:
			d[int(w)] += 1
		else:
			d[int(w)] = 1
	for i in range(5, 10):
		if d[i] != None and i != 6 and (d[6] != None):
			s = s + chr(60 + i)
		if d[i] != None and d[i] >= 2 and (i == 6):
			s = s + chr(60 + i)
	for i in range(10):
		if d[i] != None and i != 7 and (d[7] != None):
			s = s + chr(70 + i)
		if d[i] != None and d[i] >= 2 and (i == 7):
			s = s + chr(70 + i)
	for i in range(10):
		if d[i] != None and i != 8 and (d[8] != None):
			s = s + chr(80 + i)
		if d[i] != None and d[i] >= 2 and (i == 8):
			s = s + chr(80 + i)
	if d[9] != None and d[0] != None:
		s = s + chr(90)
	if len(s) == 0:
		print()
	else:
		print(s)


import sys
input = sys.stdin.readline

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

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

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

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

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

def outlt(lst):
	sys.stdout.write(' '.join(map(str, lst)) + '\n')

def outplt(lst):
	sys.stdout.write('\n'.join(map(str, lst)))

def outpltlt(lst):
	sys.stdout.write('\n'.join(map(str, (' '.join(map(str, a)) for a in lst))))
ans = []
for _ in range(inp()):
	N = insr()
	an = []
	for x in range(ord('A'), ord('Z') + 1):
		(d1, d2) = str(x)
		if d1 == d2:
			if N.count(d1) > 1:
				an.append(chr(x))
		elif d1 in N and d2 in N:
			an.append(chr(x))
	ans.append(''.join(sorted(an)))
outplt(ans)


import numpy as np
for t in range(int(input())):
	n = list(input())
	arr = [int(x) for x in n]
	num = []
	if 6 in arr:
		for i in arr:
			if i >= 5:
				num.append(6 * 10 + i)
	if 66 in num:
		num.remove(66)
	if 7 in arr:
		for i in arr:
			num.append(7 * 10 + i)
	if 77 in num:
		num.remove(77)
	if 8 in arr:
		for i in arr:
			num.append(8 * 10 + i)
	if 88 in num:
		num.remove(88)
	if 9 in arr:
		if 0 in arr:
			num.append(90)
	num = np.array(num)
	np.sort(num)
	ch = ''
	for i in np.unique(num):
		ch += chr(i)
	print(ch)


from itertools import permutations
from collections import Counter
for _ in range(int(input())):
	a = list(input())
	a = map(int, a)
	z = dict(Counter(a))
	l = list(z.keys())
	for i in sorted(z.keys()):
		j = z[i]
		if i > 5:
			if j > 1:
				for k in sorted(l):
					if i * 10 + k < 91 and i * 10 + k > 64:
						print(chr(i * 10 + k), end='')
			else:
				l.remove(i)
				for k in sorted(l):
					if i * 10 + k < 91 and i * 10 + k > 64:
						print(chr(i * 10 + k), end='')
				l.append(i)
	print()


import math
from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input()
	l = len(s)
	c = defaultdict(int)
	for ch in s:
		c[int(ch)] += 1
	for i in range(65, 91):
		l = int(i % 10)
		f = int(i // 10)
		if l == f:
			if c[l] >= 2:
				print(chr(i), end='')
		elif c[l] >= 1 and c[f] >= 1:
			print(chr(i), end='')
	print()


for _ in range(int(input())):
	n = list(map(int, input().strip()))
	arr = [0] * 10
	for i in n:
		arr[i] += 1
	q = 0
	r = 0
	ptr = 0
	for i in range(65, 91):
		q = i // 10
		r = i % 10
		if q != r:
			if arr[q] >= 1 and arr[r] >= 1:
				print(chr(i), end='')
				ptr = 1
		elif arr[q] >= 2:
			print(chr(i), end='')
			ptr = 1
	if ptr == 1:
		print()


t = int(input())
from itertools import permutations
for i in range(t):
	n = int(input())
	s = list(str(n))
	l = []
	perm = permutations(s, 2)
	perm = set(list(perm))
	for i in list(perm):
		s = ''
		s += str(i[0])
		s += str(i[1])
		s = int(s)
		if s >= 65 and s <= 90:
			l.append(chr(s))
	l.sort()
	for i in l:
		print(i, end='')
	print()


for i in range(int(input())):
	a = list(input())
	d = ''
	for i in range(65, 91, 1):
		c = list(str(i))
		count = 0
		for j in c:
			if j in a and a.count(j) >= c.count(j):
				count = count + 1
		if count == len(c):
			d = d + chr(i)
	print(d)


for i in range(int(input())):
	s = input()
	z = s
	h = ''
	l = []
	k = 0
	while len(z) != 0:
		if k >= len(z):
			break
		if int(z[k]) < 6:
			f = z[k]
			z = z.replace(f, '')
			h = h + f
		else:
			f = z[k]
			h = h + f
			k += 1
	for i in range(len(h)):
		a = int(h[i])
		if a >= 6:
			for j in range(len(h)):
				b = int(h[j])
				if a == 6 and b < 5:
					continue
				if j != i:
					n = a * 10 + b
					if n >= 65 and n <= 90:
						l.append(chr(n))
	l = set(l)
	l = list(l)
	l.sort()
	print(''.join(l))


import sys
import math

def main(arr):
	freq = {}
	for e in arr:
		s = int(e)
		if s not in freq:
			freq[s] = 0
		freq[s] += 1
	ans = []
	for i in range(65, 91):
		s = str(i)
		if int(s[0]) in freq:
			freq[int(s[0])] -= 1
			if int(s[1]) in freq and freq[int(s[1])] > 0:
				ans.append(chr(i + 32).upper())
			freq[int(s[0])] += 1
	ans = ''.join(ans)
	return ans
for _ in range(int(input())):
	n = input()
	print(main(n))


for _ in range(int(input())):
	st = input()
	alpha = {65: 'A', 66: 'B', 67: 'C', 68: 'D', 69: 'E', 70: 'F', 71: 'G', 72: 'H', 73: 'I', 74: 'J', 75: 'K', 76: 'L', 77: 'M', 78: 'N', 79: 'O', 80: 'P', 81: 'Q', 82: 'R', 83: 'S', 84: 'T', 85: 'U', 86: 'V', 87: 'W', 88: 'X', 89: 'Y', 90: 'Z'}
	ans = ''
	num_0 = st.count('0')
	num_1 = st.count('1')
	num_2 = st.count('2')
	num_3 = st.count('3')
	num_4 = st.count('4')
	num_5 = st.count('5')
	num_6 = st.count('6')
	num_7 = st.count('7')
	num_8 = st.count('8')
	num_9 = st.count('9')
	for i in range(0, 10):
		if str(i) in st:
			if num_9 > 0 and i == 0:
				ans = ans + alpha[int(str(9) + str(0))]
			if num_6 > 0 and i >= 5:
				if i == 6:
					if num_6 == 1:
						pass
					else:
						ans = ans + alpha[int(str(6) + str(6))]
				else:
					ans = ans + alpha[int(str(6) + str(i))]
			if num_7 > 0:
				if i == 7:
					if num_7 == 1:
						pass
					else:
						ans = ans + alpha[int(str(7) + str(7))]
				else:
					ans = ans + alpha[int(str(7) + str(i))]
			if num_8 > 0:
				if i == 8:
					if num_8 == 1:
						pass
					else:
						ans = ans + alpha[int(str(8) + str(8))]
				else:
					ans = ans + alpha[int(str(8) + str(i))]
	ans = sorted(ans)
	ans = ''.join(ans)
	print(ans)


test = int(input())
for i in range(test):
	N = input()
	X = []
	for x in N:
		X.append(x)
	Y = []
	list1 = []
	output = ''
	for y in X:
		if int(y) >= 6 and int(y) not in Y:
			Y.append(y)
	for x in Y:
		for y in X:
			if int(x) == 6:
				if int(y) >= 5:
					n = int(x) * 10 + int(y)
					list1.append(n)
			elif int(x) == 9:
				if int(y) == 0:
					n = int(x) * 10 + int(y)
					list1.append(n)
			else:
				n = int(x) * 10 + int(y)
				list1.append(n)
	for j in Y:
		if int(j) != 9:
			m = int(j) * 10 + int(j)
			list1.remove(m)
	list1.sort()
	if len(list1) == 0:
		print(' ')
	else:
		list1.sort()
		for k in list1:
			if chr(k) not in output:
				output += chr(k)
		print(output)


for i in range(int(input())):
	n = input()
	final = ''
	for i in range(65, 91):
		x = str(i)
		a = x[0]
		b = x[1]
		if a == b and n.count(a) >= 2:
			final += chr(i)
		elif a != b and a in n and (b in n):
			final += chr(i)
	if len(final) >= 1:
		print(final.upper())


for _ in range(int(input())):
	n = input()
	a = ''
	for i in range(65, 91):
		num = str(i)
		x = num[0]
		y = num[1]
		if x == y and n.count(x) >= 2:
			a += chr(i)
		elif x != y and x in n and (y in n):
			a += chr(i)
	if len(a) >= 1:
		print(a.upper())


from collections import Counter
for i in range(int(input())):
	n = int(input())
	a = str(n)
	ans = []
	d = Counter(a)
	for j in range(65, 91):
		k = str(j)
		if k[0] in a and k[1] in a:
			if k[0] == k[1]:
				if d[k[0]] >= 2:
					ans.append(j)
			else:
				ans.append(j)
	for j in range(len(ans)):
		print(chr(int(ans[j])), end='')
		if j == len(ans) - 1:
			print('')
	if len(ans) == 0:
		print('')


t = input()
d = {str(x): chr(x) for x in range(65, 91)}
for p in range(int(t)):
	N = input()
	S = set(N)
	fin = ''
	for (k, v) in d.items():
		if set(k).issubset(S):
			if len(set(k)) == 1:
				if N.count(k[0]) > 1:
					fin += v
			else:
				fin += v
	print(fin)


T = int(input())
while T != 0:
	inpS = input()
	uniq = sorted(set(inpS))
	solu = ''
	for i in range(0, len(uniq)):
		for j in range(0, len(uniq)):
			if i != j or inpS.count(uniq[i]) >= 2:
				chr1 = chr(int(uniq[i] + uniq[j]))
				chr2 = chr(int(uniq[j] + uniq[i]))
				if chr1 >= 'A' and chr1 <= 'Z' and (chr1 not in solu):
					solu += chr1
				if chr2 >= 'A' and chr2 <= 'Z' and (chr2 not in solu):
					solu += chr2
	solu = sorted(solu)
	answer = ''
	for i in solu:
		answer += i
	print(answer)
	T -= 1


from collections import Counter
for i in range(int(input())):
	a = [int(i) for i in str(input())]
	a1 = []
	asdf = Counter(a)
	for n in range(65, 91):
		nn = n % 10
		nn1 = n // 10
		if nn == nn1:
			if asdf[nn] >= 2:
				a1.append(chr(n))
		elif asdf[nn] > 0 and asdf[nn1] > 0:
			a1.append(chr(n))
	print() if len(a1) == 0 else print(''.join(a1))


t = int(input())
for _ in range(t):
	s = input()
	c = 0
	dic = {}
	for i in s:
		if i in dic:
			dic[i] = dic[i] + 1
		else:
			dic[i] = 1
	for i in range(65, 91, 1):
		s1 = str(i)
		if s1[0] in dic and s1[1] in dic:
			if s1[0] == s1[1]:
				if dic[s1[1]] > 1:
					print(chr(i), end='')
					c = 1
			else:
				print(chr(i), end='')
				c = 1
	if c == 1:
		print()


for _ in range(int(input())):
	n = input()
	li = []
	for i in range(65, 91):
		(l, r) = (str(i)[0], str(i)[1])
		if l == r:
			x = n.count(l)
			if x >= 2:
				li.append(chr(i))
		elif l in n and r in n:
			li.append(chr(i))
	print(*li, sep='')


for _ in range(int(input())):
	N = input()
	for i in range(65, 91):
		if i % 11 == 0:
			if N.count(str(i % 10)) >= 2:
				print(chr(i), end='')
		elif str(i % 10) in N and str(i // 10) in N:
			print(chr(i), end='')
	print()


listInput = lambda : list(map(int, input().split(' ')))
mapInput = lambda : map(int, input().split(' '))
for _ in range(int(input())):
	n = input()
	L = []
	for i in range(65, 91):
		num = str(i)
		(n1, n2) = (num[0], num[1])
		if n1 == n2 and n.count(n1) >= 2:
			L.append(chr(i))
		elif n1 != n2 and n1 in n and (n2 in n):
			L.append(chr(i))
	if len(L) >= 1:
		print(''.join(L))


T = int(input())
for t in range(T):
	N = str(input())
	val = ord('A')
	ans = ''
	for i in range(26):
		sd = val % 10
		fd = int(val / 10)
		fp = -1
		sp = -1
		fpb = False
		spb = False
		for n in range(len(N)):
			if int(N[n]) == fd:
				fp = n
				fpb = True
				break
		for j in range(len(N)):
			if int(N[j]) == sd:
				if j != n:
					sp = j
					spb = True
					break
		if spb == fpb and spb == True:
			ans = ans + chr(val)
		val = val + 1
	print(ans)


for _ in range(int(input())):
	num = input()
	sol = ''
	temp = set(num)
	for i in range(65, 91):
		if i // 10 == i % 10:
			if num.count(str(i // 10)) >= 2:
				sol += chr(i)
		elif str(i // 10) in temp and str(i % 10) in temp:
			sol += chr(i)
	print(sol)


t = int(input())
from itertools import permutations
for i in range(t):
	n = int(input())
	s = list(str(n))
	l = [0] * 10
	for i in s:
		if l[0] >= 1 and l[1] >= 1 and (l[2] >= 1) and (l[3] >= 1) and (l[4] >= 1) and (l[5] >= 1) and (l[6] >= 2) and (l[7] >= 2) and (l[8] >= 2) and (l[9] >= 1):
			break
		if i == '0':
			l[0] += 1
		elif i == '1':
			l[1] += 1
		elif i == '2':
			l[2] += 1
		elif i == '3':
			l[3] += 1
		elif i == '4':
			l[4] += 1
		elif i == '5':
			l[5] += 1
		elif i == '6':
			l[6] += 1
		elif i == '7':
			l[7] += 1
		elif i == '8':
			l[8] += 1
		elif i == '9':
			l[9] += 1
	x = []
	for i in range(10):
		if l[i] >= 1 and i != 8 and (i != 6) and (i != 7):
			x.append(i)
		elif i == 6 or i == 7 or i == 8:
			if l[i] >= 2:
				x.append(i)
				x.append(i)
			elif l[i] == 1:
				x.append(i)
	perm = permutations(x, 2)
	perm = set(list(perm))
	l1 = []
	for i in list(perm):
		s = ''
		s += str(i[0])
		s += str(i[1])
		s = int(s)
		if s >= 65 and s <= 90:
			l1.append(chr(s))
	l1.sort()
	for i in l1:
		print(i, end='')
	print()


for _ in range(int(input())):
	n = input()
	d = {}
	s = ''
	for i in n:
		d[i] = d.get(i, 0) + 1
	for i in range(65, 91):
		k = str(i)
		if k[0] == k[1]:
			if d.get(k[0], 0) > 1:
				s += chr(i)
		elif d.get(k[0], 0) != 0 and d.get(k[1], 0) != 0:
			s += chr(i)
	print(s)


for i in range(int(input())):
	n = str(input())
	a = []
	b = []
	s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	for i in n:
		if i not in a:
			a.append(i)
		elif (i == '6' or i == '7' or i == '8') and i not in b:
			b.append(i)
	ans = ''
	a.sort()
	b.sort()
	for i in a:
		for j in a:
			if i != j or i in b:
				v = int(i + j)
				if v >= 65 and v <= 90:
					v = v - 65
					ans = ans + s[v]
	print(ans)


for _ in range(int(input())):
	a = input()
	b = []
	t = list(range(0, 10))
	for i in t:
		C = 0
		for j in a:
			if i == int(j):
				C += 1
				if C == 2:
					break
		if C == 1:
			b.append(i)
		elif C == 2:
			b.append(i)
			b.append(i)
	l2 = []
	l = len(b)
	for i in range(0, l):
		if b[i] > 5:
			for j in range(0, l):
				if b[i] == 6 and b[j] < 5 or i == j or (b[i] == 9 and b[j] > 0):
					continue
				c = 10 * b[i] + b[j]
				l2.append(chr(c))
	l2 = sorted(set(l2))
	if len(l2) == 0:
		continue
	for i in l2:
		print(i, end='')
	print('')


for i in range(int(input())):
	s = input()
	l = []
	for i in range(len(s)):
		a = int(s[i])
		if a >= 6:
			for j in range(len(s)):
				b = int(s[j])
				if a == 6 and b < 5:
					continue
				if j != i:
					n = a * 10 + b
					if n >= 65 and n <= 90:
						l.append(chr(n))
	l = set(l)
	l = list(l)
	l.sort()
	print(''.join(l))


t = int(input())
for i in range(t):
	a = [0] * 100
	b = [0] * 10
	s = ''
	n = list(map(int, str(input())))
	for i in n:
		b[i] = b[i] + 1
	for i in range(6, 10):
		if b[i] > 0:
			for j in range(10):
				if b[j] <= 1 and i == j:
					continue
				if b[j] > 0:
					a[i + j * 10] = a[i + j * 10] + 1
					a[j + i * 10] = a[j + i * 10] + 1
	for i in range(26):
		if a[65 + i] > 0:
			s = s + chr(65 + i)
	print(s)


import math
from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input()
	l = len(s)
	count = defaultdict(int)
	for ch in s:
		count[int(ch)] += 1
	for ascii in range(65, 91):
		lastDigit = int(ascii % 10)
		firstDigit = int(ascii // 10)
		if lastDigit == firstDigit:
			if count[lastDigit] >= 2:
				print(chr(ascii), end='')
		elif count[lastDigit] >= 1 and count[firstDigit] >= 1:
			print(chr(ascii), end='')
	print()


n = int(input())
for i in range(n):
	st = input()
	output = ''
	arr = []
	dict = {}
	for i in st:
		if int(i) > 5:
			arr.append(i)
		if i in dict:
			dict[i] += 1
		else:
			dict[i] = 1
	for i in set(arr):
		for key in dict:
			if key != i or dict[key] > 1:
				ch = i + key
				if 64 < int(ch) < 91:
					output += chr(int(ch))
	print(''.join(sorted(output)))


from itertools import permutations
for _ in range(int(input())):
	a = list(input())
	for i in sorted(set(permutations(a, 2))):
		c = int(i[0]) * 10 + int(i[1])
		if c >= 65 and c < 91:
			print(chr(c), end='')
	print('')


tests = int(input())
for i in range(tests):
	num = input()
	unique_dict = {}
	for j in num:
		if j in unique_dict:
			unique_dict[j] += 1
		else:
			unique_dict[j] = 1
	ans = ''
	for j in range(65, 91):
		ascii_j = str(j)
		flag = True
		for k in ascii_j:
			if k not in unique_dict or ascii_j.count(k) > unique_dict[k]:
				flag = False
				break
		if flag:
			ans += chr(j)
	if ans:
		print(ans)


for t in range(int(input())):
	s = input()
	for i in range(65, 91):
		(a, b) = (i // 10, i % 10)
		if a == b:
			if s.count(str(a)) > 1:
				print(chr(i), end='')
		elif s.count(str(a)) > 0 and s.count(str(b)) > 0:
			print(chr(i), end='')
	print()


from math import gcd, sqrt, ceil, floor, log10
from heapq import heapify, heappop, heappush, nsmallest, nlargest
from collections import Counter, deque, OrderedDict, defaultdict
from itertools import combinations, permutations, zip_longest
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
import sys
import time
import string
import operator
sys.setrecursionlimit(3000000)
INT_MAX = float('inf')
INT_MIN = float('-inf')
MOD = int(1000000000.0) + 7
NEWLINE = '\n'
SPACE = ' '
inp = lambda fn: fn(input())
inp_vars = lambda fn, delim, convert_to=list: convert_to(map(fn, input().split(delim)))

def solve(*args, **kwargs):
	s = args[0]
	mp = Counter(map(int, s))
	res = ''
	for ascii_ in range(65, 91):
		(first, last) = divmod(ascii_, 10)
		if first in mp and last in mp:
			if first != last:
				res += chr(ascii_)
			elif first == last and mp[first] > 1:
				res += chr(ascii_)
	return res

def main(*args, **kwargs):
	for _ in range(int(input())):
		arg2 = inp(str)
		res = solve(*(arg2,))
		if type(res) in {list, tuple, set}:
			print(*res, sep=' ')
		else:
			print(res)
main()


for _ in range(int(input())):
	st = input()
	d = {}
	for i in st:
		n = int(i)
		if n in d:
			d[n] += 1
		else:
			d[n] = 1
	for i in range(65, 91):
		if i == 66 or i == 77 or i == 88:
			if i % 10 in d and d[i % 10] >= 2:
				print(chr(i), end='')
		else:
			n = i
			check = True
			while n > 0:
				if n % 10 not in d or (d[n % 10] < 1 and i in [66, 77, 88]):
					check = False
				n //= 10
			if check:
				print(chr(i), end='')
	print()


for _ in range(int(input())):
	s = input()
	lst = []
	N = len(s)
	for i in range(65, 91):
		(a, b) = (i // 10, i % 10)
		if a == b:
			if s.count(str(a)) > 1:
				print(chr(i), end='')
		elif s.count(str(a)) > 0 and s.count(str(b)) > 0:
			print(chr(i), end='')
	print()


for _ in range(int(input())):
	s = input()
	cnt = [0] * 10
	for i in s:
		cnt[ord(i) - 48] += 1
	answer = -1
	result = ''
	for i in range(65, 91):
		(a, b) = (i // 10, i % 10)
		answer += 1
		if a == b:
			if cnt[a] < 2:
				continue
			result = result + chr(65 + answer)
		elif cnt[a] >= 1 and cnt[b] >= 1:
			result = result + chr(65 + answer)
	if len(result) == 0:
		pass
	else:
		print(result)


t = int(input())
for i in range(t):
	n = input()
	c = []
	for j in range(65, 91):
		(l, r) = (str(j)[0], str(j)[1])
		if l != r:
			if l in n and r in n:
				c.append(chr(j))
		else:
			x = n.count(l)
			if x >= 2:
				c.append(chr(j))
	print(*c, sep='')


import sys
input = sys.stdin.readline

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

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

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

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

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

def outlt(lst):
	sys.stdout.write(' '.join(map(str, lst)) + '\n')

def outplt(lst):
	sys.stdout.write('\n'.join(map(str, lst)))

def outpltlt(lst):
	sys.stdout.write('\n'.join(map(str, (' '.join(map(str, a)) for a in lst))))
Six = ['', '', '', '', '', 'A', 'B', 'C', 'D', 'E']
Sev = ['F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O']
Eig = ['P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y']
ans = []
for _ in range(inp()):
	N = insr()
	dig = [0] * 10
	an = []
	for x in range(10):
		if str(x) in N:
			dig[x] = 1
	if dig[6]:
		an.extend([Six[x] for x in range(10) if dig[x]])
		if N.count('6') == 1:
			an.remove('B')
	if dig[7]:
		an.extend([Sev[x] for x in range(10) if dig[x]])
		if N.count('7') == 1:
			an.remove('M')
	if dig[8]:
		an.extend([Eig[x] for x in range(10) if dig[x]])
		if N.count('8') == 1:
			an.remove('X')
	if dig[9] and dig[0]:
		an.append('Z')
	ans.append(''.join(sorted(an)))
outplt(ans)


for _ in range(int(input())):
	s = list(map(int, input()))
	freq = [0] * 10
	for i in s:
		freq[i - 1] += 1
	fin_arr = []
	for i in range(65, 91):
		first = i // 10 % 10
		second = i % 10
		if first == second:
			if freq[first - 1] > 1:
				print(chr(i), end='')
		elif freq[first - 1] > 0 and freq[second - 1] > 0:
			print(chr(i), end='')
	print()


import sys
input = sys.stdin.readline

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

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

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

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

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

def outlt(lst):
	sys.stdout.write(' '.join(map(str, lst)) + '\n')

def outplt(lst):
	sys.stdout.write('\n'.join(map(str, lst)))

def outpltlt(lst):
	sys.stdout.write('\n'.join(map(str, (' '.join(map(str, a)) for a in lst))))
ans = []
for _ in range(inp()):
	N = insr()
	dig = {}
	for x in N:
		if x in dig:
			dig[x] += 1
		else:
			dig[x] = 1
	an = []
	if '6' in dig:
		an.extend([chr(int('6' + x)) for x in dig if x in '56789'])
	if '7' in dig:
		an.extend([chr(int('7' + x)) for x in dig])
	if '8' in dig:
		an.extend([chr(int('8' + x)) for x in dig])
	if '9' in dig and '0' in dig:
		an.append('Z')
	if '6' in dig and dig['6'] == 1:
		an.remove('B')
	if '7' in dig and dig['7'] == 1:
		an.remove('M')
	if '8' in dig and dig['8'] == 1:
		an.remove('X')
	an = ''.join(sorted(an))
	ans.append(an)
outplt(ans)


tests = int(input())
for i in range(tests):
	num = input()
	ans = ''
	for j in range(65, 91):
		ascii_j = str(j)
		if ascii_j[0] == ascii_j[1] and num.count(ascii_j[0]) >= 2:
			ans += chr(j)
		elif ascii_j[0] != ascii_j[1] and num.count(ascii_j[0]) >= 1 and (num.count(ascii_j[1]) >= 1):
			ans += chr(j)
	if ans:
		print(ans)


test = int(input())
for i in range(test):
	N = input()
	X = []
	list2 = []
	for x in N:
		X.append(x)
	list1 = []
	list1 = list(set(X))
	output = ''
	for x in list1:
		for y in X:
			if int(x) >= 6:
				n = int(x) * 10 + int(y)
				list2.append(n)
	for j in list1:
		if int(j) >= 6:
			m = int(j) * 10 + int(j)
			list2.remove(m)
	list2.sort()
	if len(list2) == 0:
		print(' ')
	else:
		list2.sort()
		for k in list2:
			if chr(k) not in output and 64 < k < 91:
				output += chr(k)
		print(output)


from math import *
import sys

def input():
	return sys.stdin.readline().replace('\n', '').strip()
sys.setrecursionlimit(10 ** 9)
for _ in range(int(input())):
	n = input()
	s = ''
	for i in range(10):
		if n.count(str(i)) >= 2:
			s += str(i)
			s += str(i)
		elif n.count(str(i)) == 1:
			s += str(i)
	n1 = len(s)
	l1 = set()
	for i in range(n1):
		for j in range(i + 1, n1):
			l1.add(int(s[i] + s[j]))
			l1.add(int(s[j] + s[i]))
	l2 = []
	for i in l1:
		if 65 <= i <= 90:
			l2.append(chr(i))
	l2.sort()
	for i in l2:
		print(i, end='')
	print()


from collections import defaultdict
for _ in range(int(input())):
	s = input()
	l = len(s)
	count = defaultdict(int)
	for ch in s:
		count[int(ch)] += 1
	for ascii in range(65, 91):
		firstdigit = int(ascii // 10)
		lastdigit = int(ascii % 10)
		if lastdigit == firstdigit:
			if count[lastdigit] > 1:
				print(chr(ascii), end='')
		elif count[lastdigit] > 0 and count[firstdigit] > 0:
			print(chr(ascii), end='')
	print()