Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all $26$ lowercase Latin letters will be arranged in some order.

Polycarp uses the same password $s$ on all websites where he is registered (it is bad, but he doesn't care). He wants to assemble a keyboard that will allow to type this password very easily. He doesn't like to move his fingers while typing the password, so, for each pair of adjacent characters in $s$, they should be adjacent on the keyboard. For example, if the password is abacaba, then the layout cabdefghi... is perfect, since characters a and c are adjacent on the keyboard, and a and b are adjacent on the keyboard. It is guaranteed that there are no two adjacent equal characters in $s$, so, for example, the password cannot be password (two characters s are adjacent).

Can you help Polycarp with choosing the perfect layout of the keyboard, if it is possible?


-----Input-----

The first line contains one integer $T$ ($1 \le T \le 1000$) — the number of test cases.

Then $T$ lines follow, each containing one string $s$ ($1 \le |s| \le 200$) representing the test case. $s$ consists of lowercase Latin letters only. There are no two adjacent equal characters in $s$.


-----Output-----

For each test case, do the following:

  if it is impossible to assemble a perfect keyboard, print NO (in upper case, it matters in this problem);  otherwise, print YES (in upper case), and then a string consisting of $26$ lowercase Latin letters — the perfect layout. Each Latin letter should appear in this string exactly once. If there are multiple answers, print any of them. 


-----Example-----
Input
5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza

Output
YES
bacdefghijklmnopqrstuvwxyz
YES
edocabfghijklmnpqrstuvwxyz
NO
YES
xzytabcdefghijklmnopqrsuvw
NO

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Graph traversal

Implementation

Greedy algorithms


Solutions:
testCases = int(input())
for i1 in range(testCases):
	used = [False] * 26
	s = input()
	t = s[0]
	used[ord(s[0]) - ord('a')] = True
	pos = 0
	result = 'YES'
	for i2 in range(1, len(s), 1):
		if used[ord(s[i2]) - ord('a')]:
			if pos > 0 and t[pos - 1] == s[i2]:
				pos -= 1
			elif pos < len(t) - 1 and t[pos + 1] == s[i2]:
				pos += 1
			else:
				result = 'NO'
				break
		elif pos == 0:
			t = s[i2] + t
		elif pos == len(t) - 1:
			t += s[i2]
			pos += 1
		else:
			result = 'NO'
			break
		used[ord(s[i2]) - ord('a')] = True
	for i2 in range(26):
		if not used[i2]:
			t += chr(i2 + ord('a'))
	print(result)
	if result == 'YES':
		print(t)


from collections import defaultdict
al = [chr(ord('a') + i) for i in range(26)]
t = int(input())
for _ in range(t):
	a = input()
	d = defaultdict(lambda : set())
	for (u, v) in zip(a, a[1:]):
		d[u].add(v)
		d[v].add(u)
	s = None
	x = False
	for (i, v) in d.items():
		if len(v) > 2:
			x = True
			break
		elif len(v) == 1:
			s = i
	if len(d) == 0:
		print('YES')
		print(''.join(al))
	elif x or s is None:
		print('NO')
	else:
		z = [s, d[s].pop()]
		while True:
			(p, q) = (z[-1], z[-2])
			d[p].discard(q)
			if d[p]:
				z.append(d[p].pop())
			else:
				break
		print('YES')
		print(''.join(z) + ''.join((b for b in al if b not in z)))


from sys import stdin
from collections import deque
input = stdin.readline

def getAns(s):
	keyboard = deque()
	keyboard.appendleft(s[0])
	alphabet = ['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']
	alphabet.remove(s[0])
	for i in range(1, len(s)):
		if s[i] not in keyboard:
			if keyboard.index(s[i - 1]) == 0:
				keyboard.appendleft(s[i])
			elif keyboard.index(s[i - 1]) == len(keyboard) - 1:
				keyboard.append(s[i])
			else:
				print('NO')
				return
			alphabet.remove(s[i])
		elif abs(keyboard.index(s[i]) - keyboard.index(s[i - 1])) > 1:
			print('NO')
			return
	print('YES')
	print(''.join(keyboard) + ''.join(alphabet))
for _ in range(int(input())):
	getAns(list(input().rstrip()))


from collections import deque
t = int(input())
abc = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(t):
	s = input()
	d = deque(list(s[0]))
	res = False
	a = set()
	for i in range(1, len(s)):
		if len(d) != 1 and d[0] == d[-1]:
			res = True
			break
		if s[i] + s[i - 1] in a or s[i - 1] + s[i] in a:
			pass
		elif s[i - 1] == d[0]:
			d.appendleft(s[i])
			a.add(s[i] + s[i - 1])
		elif s[i - 1] == d[-1]:
			d.append(s[i])
			a.add(s[i] + s[i - 1])
		else:
			res = True
			break
	if res or (len(d) != 1 and d[0] == d[-1]):
		print('NO')
	else:
		ans = list(d)
		count = len(d)
		d = set(d)
		for i in abc:
			if i not in d:
				ans.append(i)
		if len(ans) != 26:
			print('NO')
		else:
			print('YES')
			print(*ans, sep='')


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')
testcases = int(input())
for j in range(testcases):
	string = input()
	dict1 = {}
	broke = False
	if len(string) == 1:
		outy = [chr(s + 97) for s in range(26)]
		print('YES')
		print(''.join(outy))
	else:
		for s in range(len(string)):
			for k in range(len(string)):
				if string[k] == string[s]:
					if k == 0:
						rightval = string[k + 1]
						if not string[s] in dict1:
							dict1[string[s]] = set([rightval])
						else:
							dict1[string[s]].add(rightval)
					elif k == len(string) - 1:
						leftval = string[k - 1]
						if not string[s] in dict1:
							dict1[string[s]] = set([leftval])
						else:
							dict1[string[s]].add(leftval)
					else:
						leftval = string[k - 1]
						if not string[s] in dict1:
							dict1[string[s]] = set([leftval])
						else:
							dict1[string[s]].add(leftval)
						rightval = string[k + 1]
						if not string[s] in dict1:
							dict1[string[s]] = set([rightval])
						else:
							dict1[string[s]].add(rightval)
					if len(dict1[string[s]]) > 2:
						broke = True
						break
		if broke == True:
			print('NO')
		else:
			startval = 0
			found = False
			for s in dict1.keys():
				if len(dict1[s]) == 1:
					startval = s
					found = True
					break
			if found == False:
				print('NO')
			else:
				outy = [startval]
				while len(outy) < len(dict1.keys()):
					nextval = list(dict1[outy[-1]])
					if len(nextval) == 2:
						nextval.remove(outy[-2])
					outy.append(nextval[0])
				for s in range(26):
					val = chr(s + 97)
					if not val in outy:
						outy.append(val)
				print('YES')
				print(''.join(outy))


from collections import deque, Counter
import array
from itertools import combinations, permutations
from math import sqrt

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

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

class Node:

	def __init__(self, c):
		self.c = c
		self.l = None
		self.r = None
tests = read_int()
for test in range(tests):
	s = input().strip()
	left = Node(s[0])
	x = left
	found = True
	used = set([x.c])
	for c in s[1:]:
		if x.c == c:
			continue
		if x.l and x.l.c == c:
			x = x.l
		elif x.r and x.r.c == c:
			x = x.r
		elif not x.l and c not in used:
			x.l = Node(c)
			used.add(c)
			x.l.r = x
			x = x.l
			left = x
		elif not x.r and c not in used:
			x.r = Node(c)
			used.add(c)
			x.r.l = x
			x = x.r
		else:
			found = False
			break
	if not found:
		print('NO')
	else:
		ans = []
		x = left
		while x:
			ans.append(x.c)
			x = x.r
		for c in 'abcdefghijklmnopqrstuvwxyz':
			if c not in used:
				ans.append(c)
		print('YES')
		print(''.join(ans))


visited = []
a = []
res = ''

def charToInt(x):
	return ord(x) - 97

def intToChar(x):
	return chr(x + 97)

def dfs(x):
	global visited
	global a
	global res
	res += intToChar(x)
	visited[x] = True
	for e in a[x]:
		if not visited[e]:
			dfs(e)

def run():
	fullAlb = 'abcdefghijklmnopqrstuvwxyz'
	s = str(input())
	if len(s) == 1:
		print('YES')
		print(fullAlb)
		return
	global a
	global visited
	global res
	res = ''
	a = [[] for i in range(26)]
	for i in range(len(s) - 1):
		a[charToInt(s[i])].append(charToInt(s[i + 1]))
		a[charToInt(s[i + 1])].append(charToInt(s[i]))
	if len(s) > 2:
		a[charToInt(s[-1])].append(charToInt(s[-2]))
		a[charToInt(s[-2])].append(charToInt(s[-1]))
	for i in range(26):
		a[i] = set(a[i])
		if len(a[i]) > 2:
			print('NO')
			return
	visited = [False for i in range(26)]
	for i in range(26):
		if not visited[i] and len(a[i]) == 1:
			dfs(i)
	for i in range(26):
		if not visited[i]:
			if len(a[i]) > 0:
				print('NO')
				return
			else:
				res += intToChar(i)
	print('YES')
	print(res)
t = int(input())
while t > 0:
	run()
	t -= 1


import string
t = int(input())
for i in range(t):
	s = list(input())
	res = []
	sets = []
	yes = True
	res.append(' ')
	res.append(s[0])
	sets.append(s[0])
	res.append(' ')
	curind = res.index(s.pop(0))
	for k in range(len(s)):
		if s[0] not in sets:
			if res[curind + 1] != ' ':
				if res[curind - 1] != ' ':
					yes = False
				else:
					res[curind - 1] = s[0]
					sets.append(s.pop(0))
					res.insert(0, ' ')
			else:
				res[curind + 1] = s[0]
				sets.append(s.pop(0))
				curind += 1
				res.append(' ')
		elif res[curind - 1] == s[0]:
			curind -= 1
			s.pop(0)
		elif res[curind + 1] == s[0]:
			curind += 1
			s.pop(0)
		else:
			yes = False
	res = ''.join(res).strip(' ')[::-1]
	if yes:
		print('YES')
		print(res, end='')
		for j in range(len(string.ascii_lowercase)):
			if string.ascii_lowercase[j] not in res:
				print(string.ascii_lowercase[j], end='')
		print('')
	else:
		print('NO')


def dfs(s):
	print(chr(ord('a') + s), end='')
	visit[s] = 1
	for i in range(len(adj[s])):
		if visit[adj[s][i]] == 0:
			dfs(adj[s][i])
for t in range(int(input())):
	s = input()
	adj = [[] for i in range(26)]
	dt = 1
	for i in range(1, len(s)):
		l = ord(s[i - 1]) - ord('a')
		k = ord(s[i]) - ord('a')
		co = 1
		for r in adj[l]:
			if r == k:
				co = 0
				break
		if co:
			adj[l].append(k)
		co = 1
		for r in adj[k]:
			if r == l:
				co = 0
				break
		if co:
			adj[k].append(l)
		if len(adj[k]) > 2 or len(adj[l]) > 2:
			dt = 0
			break
	visit = [0] * 26
	con = 0
	for i in range(26):
		if len(adj[i]) == 1:
			con = 1
	if dt and con or len(s) == 1:
		print('YES')
		for i in range(26):
			if visit[i] == 0 and len(adj[i]) < 2:
				dfs(i)
		print()
	else:
		print('NO')


T = int(input())
for _ in range(0, T):
	s = input()
	if len(s) == 1:
		print('YES')
		print(s[0], end='')
		for i in range(0, 26):
			if chr(i + 97) != s[0]:
				print(chr(i + 97), end='')
		print(' ')
	else:
		pos = []
		for i in range(26):
			h = []
			pos.append(h)
		for i in range(0, len(s)):
			if i - 1 >= 0:
				pos[ord(s[i]) - 97].append(ord(s[i - 1]) - 97)
			if i + 1 < len(s):
				pos[ord(s[i]) - 97].append(ord(s[i + 1]) - 97)
		for i in range(0, len(pos)):
			pos[i] = list(set(pos[i]))
		temp = 0
		flag = 0
		for i in range(0, len(pos)):
			if len(pos[i]) > 2:
				flag = 1
				break
			if len(pos[i]) == 1:
				temp += 1
		if temp != 2 or flag == 1:
			print('NO')
		else:
			print('YES')
			vis = [False] * 26
			ptr = 0
			for i in range(0, len(pos)):
				if len(pos[i]) == 1:
					ptr = i
					break
			tt = 0
			while tt == 0:
				vis[ptr] = True
				print(chr(ptr + 97), end='')
				ct = 0
				for i in pos[ptr]:
					if vis[i] == False:
						vis[i] = True
						ptr = i
						ct = 1
						break
				if ct == 0:
					tt = 1
					break
			for i in range(0, 26):
				if vis[i] == False:
					print(chr(i + 97), end='')
			print(' ')


import math
from collections import defaultdict, Counter, deque
import os
import sys
from io import BytesIO, IOBase
ii = lambda : int(input())
lmii = lambda : list(map(int, input().split()))
slmii = lambda : sorted(map(int, input().split()))
li = lambda : list(input())
mii = lambda : map(int, input().split())
msi = lambda : map(str, input().split())

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

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

def main():
	for _ in ' ' * int(input()):
		s = li()
		n = len(s)
		d = defaultdict(set)
		if n == 1:
			print('YES\nabcdefghijklmnopqrstuvwxyz')
		else:
			f = 0
			for i in range(n):
				if i:
					d[s[i]].add(s[i - 1])
				if i != n - 1:
					d[s[i]].add(s[i + 1])
			for i in d:
				if len(d[i]) > 2:
					print('NO')
					f = 1
					break
			if not f:
				val = -1
				for i in d:
					if len(d[i]) == 1:
						val = i
						break
				if val == -1:
					print('NO')
				else:
					print('YES')
					st = [val]
					vis = defaultdict(int)
					while st:
						print(st[-1], end='')
						ele = st[-1]
						st.pop()
						vis[ele] = 1
						for i in d[ele]:
							if not vis[i]:
								st.append(i)
					for i in 'abcdefghijklmnopqrstuvwxyz':
						if not vis[i]:
							print(i, end='')
					print()
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 o9(x):
	return ord(x) - 97

def fprint(x):
	global m
	if m:
		m = False
		print(x)
ab = [i for i in range(26)]
abb = ['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']
for _ in range(int(input())):
	m = True
	s = input()
	uv = [[] for i in range(26)]
	nj = o9(s[0])
	for ii in range(len(s) - 1):
		(j, nj) = (nj, o9(s[ii + 1]))
		if not nj in uv[j]:
			uv[j].append(nj)
			uv[nj].append(j)
	ind = -1
	for i in range(26):
		if len(uv[i]) > 2:
			fprint('NO')
			break
		elif len(uv[i]) == 1:
			ind = i
	else:
		used = set()
		ans = ''
		while len(used) != 26:
			ind = -1
			for i in range(26):
				if not i in used and len(uv[i]) <= 1:
					ind = i
					break
			if ind == -1:
				fprint('NO')
				break
			else:
				ans += abb[ind]
				used.add(ind)
				if len(uv[ind]) == 1:
					(oind, ind) = (ind, uv[ind].pop())
					while ind != -1:
						if ind in used:
							fprint('NO')
							break
						else:
							uv[ind].remove(oind)
							ans += abb[ind]
							used.add(ind)
							if len(uv[ind]) == 1:
								(oind, ind) = (ind, uv[ind].pop())
							else:
								ind = -1
		if m:
			print('YES', '\n', ans)


t = int(input())
from string import ascii_lowercase
strings = ascii_lowercase
while t > 0:
	out = [0] * 100
	st = 50
	s = input()
	d = {}
	ans = True
	d[s[0]] = st
	out[st] = s[0]
	for i in range(1, len(s)):
		currel = s[i]
		k = d[s[i - 1]]
		if s[i] not in d:
			if out[k - 1] == 0:
				out[k - 1] = s[i]
				d[s[i]] = k - 1
			elif out[k + 1] == 0:
				out[k + 1] = s[i]
				d[s[i]] = k + 1
			else:
				ans = False
				break
		else:
			k = d[s[i]]
			currel = s[i - 1]
			if out[k - 1] == currel or out[k + 1] == currel:
				continue
			else:
				ans = False
				break
	if ans == False:
		print('NO')
	else:
		temp = ''
		arr = []
		for i in out:
			if i != 0:
				arr.append(i)
		for i in strings:
			if i in d:
				continue
			else:
				arr.append(i)
		print('YES')
		print(temp.join(arr))
	t -= 1


for s in range(int(input())):
	string = input()
	reach = [0 for i in range(59)]
	visited = [0 for i in range(26)]
	k = 27
	flag = 0
	for i in string:
		if visited[ord(i) % 97] == 0:
			visited[ord(i) % 97] = 1
			if reach[k + 1] == 0 or reach[k - 1] == 0:
				if reach[k + 1] == 0:
					k += 1
					reach[k] = i
				else:
					k -= 1
					reach[k] = i
			else:
				flag = -1
				break
		else:
			if reach[k + 1] != 0 and reach[k - 1] != 0:
				if reach[k + 1] != i and reach[k] != i and (reach[k - 1] != i):
					flag = -1
					break
				else:
					flag = 1
			elif reach[k + 1] != i and reach[k] != i and (reach[k - 1] != i):
				flag = -1
				break
			else:
				flag = 1
			if flag == 1:
				if reach[k + 1] == i:
					k += 1
				elif reach[k - 1] == i:
					k -= 1
	if flag == -1:
		print('NO')
		continue
	rama = []
	for i in reach:
		if i != 0:
			rama.append(i)
	for i in range(26):
		if visited[i] == False:
			rama.append(chr(97 + i))
	print('YES')
	for i in rama:
		print(i, end='')
	print()


t = int(input())
for k in range(t):
	s = input()
	n = len(s)
	ans = []
	cou = []
	for i in range(60):
		ans.append('-')
	for i in range(26):
		cou.append(0)
	now = 30
	ans[now] = s[0]
	cou[ord(s[0]) - ord('a')] = 1
	flag = 1
	for i in range(1, n):
		if ans[now - 1] == s[i]:
			now -= 1
		elif ans[now + 1] == s[i]:
			now += 1
		elif cou[ord(s[i]) - ord('a')] == 1:
			flag = 0
			break
		else:
			cou[ord(s[i]) - ord('a')] = 1
			if ans[now - 1] == '-':
				ans[now - 1] = s[i]
				now -= 1
			elif ans[now + 1] == '-':
				ans[now + 1] = s[i]
				now += 1
			else:
				flag = 0
				break
	if flag:
		print('YES')
		for i in range(60):
			if ans[i] != '-':
				print(ans[i], end='')
		for i in range(26):
			if cou[i] == 0:
				print(chr(i + ord('a')), end='')
		print()
	else:
		print('NO')


for i in range(int(input())):
	a = ''
	b = set(list('bacdefghijklmnopqrstuvwxyz'))
	r = True
	i = -1
	for x in input():
		if not a:
			a += x
			i = 0
			b.discard(x)
			continue
		if x in b:
			if r and len(a) - 1 == i:
				a += x
				i += 1
			elif i == 0:
				a = x + a
			else:
				print('NO')
				break
			b.discard(x)
			continue
		if i == len(a) - 1:
			if a[i - 1] == x:
				i -= 1
			else:
				print('NO')
				break
		elif i == 0:
			if a[i + 1] == x:
				i += 1
			else:
				print('NO')
				break
		elif a[i + 1] == x:
			i += 1
		elif a[i - 1] == x:
			i -= 1
		else:
			print('NO')
			break
	else:
		while b:
			a += b.pop()
		print('YES')
		print(a)


def test(d):
	nb1 = 0
	for i in d:
		if len(d[i]) > 2:
			return False
		elif len(d[i]) == 1:
			nb1 += 1
	return nb1 == 2
t = int(input())
for j in range(t):
	ch = input()
	d = {'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': []}
	for i in range(len(ch) - 1):
		if ch[i] not in d[ch[i + 1]]:
			d[ch[i + 1]].append(ch[i])
		if ch[i + 1] not in d[ch[i]]:
			d[ch[i]].append(ch[i + 1])
	if test(d) and len(ch) > 0:
		print('YES')
		for i in range(len(ch)):
			if len(d[ch[i]]) == 1:
				x = ch[i]
				break
		ch = x
		x = d[x][0]
		ch = ch + x
		while len(d[x]) != 1:
			a = d[x][0]
			b = d[x][1]
			if a == ch[-2]:
				a = b
			x = a
			ch = ch + x
		for i in d:
			if len(d[i]) == 0:
				ch += i
		print(ch)
	elif len(ch) == 1:
		ch = ''
		for i in d:
			ch += i
		print('YES')
		print(ch)
	else:
		print('NO')


from math import ceil, floor
from collections import deque
t = int(input())
while t:
	l = deque([])
	vis = [0] * 26
	s = input()
	n = len(s)
	j = 0
	l.append(s[0])
	ind = ord(s[0]) - ord('a')
	vis[ind] = 1
	lol = 0
	for i in range(1, n):
		ind = ord(s[i]) - ord('a')
		if vis[ind] == 0:
			if j == len(l) - 1:
				vis[ind] = 1
				l.append(s[i])
				j += 1
			elif j == 0:
				vis[ind] = 1
				l.appendleft(s[i])
			else:
				lol = 1
				break
		elif j - 1 >= 0 and s[i] == l[j - 1]:
			j -= 1
		elif j + 1 < len(l) and s[i] == l[j + 1]:
			j += 1
		else:
			lol = 1
			break
	if lol:
		print('NO')
	else:
		print('YES')
		for i in range(26):
			if vis[i] == 0:
				c = chr(ord('a') + i)
				l.append(c)
		print(*l, sep='')
	t -= 1


T = int(input())
for ijkl in range(T):
	s = input()
	g = [[] for i in range(26)]
	for i in range(len(s) - 1):
		prev = ord(s[i]) - ord('a')
		nextt = ord(s[i + 1]) - ord('a')
		if nextt not in g[prev]:
			g[prev].append(nextt)
			g[nextt].append(prev)
	ones = []
	for i in range(26):
		if len(g[i]) == 1:
			ones.append(i)
	ok = True
	ans = ''
	used = [False for i in range(26)]
	for x in ones:
		if used[x] == True:
			continue
		used[x] = True
		ans += chr(x + ord('a'))
		v = g[x][0]
		used[v] = True
		prev = x
		while len(g[v]) != 1:
			used[v] = True
			ans += chr(v + ord('a'))
			if len(g[v]) > 2:
				ok = False
				break
			new_prev = v
			if g[v][0] == prev:
				v = g[v][1]
			else:
				v = g[v][0]
			prev = new_prev
		used[v] = True
		ans += chr(v + ord('a'))
		if not ok:
			break
	for i in range(26):
		if used[i] == False:
			if len(g[i]) != 0:
				ok = False
	if not ok:
		print('NO')
	else:
		for i in range(26):
			if not used[i]:
				ans += chr(i + ord('a'))
		print('YES')
		print(ans)


n = int(input())
import string
B = [chr(i) for i in range(ord('a'), ord('z') + 1)]
D = {}
for i in range(26):
	D[B[i]] = i
for i in range(n):
	no = 0
	s = input()
	m = len(s)
	if m == 1:
		print('YES')
		print(''.join(B))
	else:
		A = [[0] * 26 for i in range(26)]
		for j in range(m - 1):
			A[D[s[j]]][D[s[j + 1]]] = 1
			A[D[s[j + 1]]][D[s[j]]] = 1
		s1 = []
		for j in range(26):
			su = sum(A[j])
			if su > 2:
				no = 1
			elif su == 1:
				s1.append(j)
		if len(s1) != 2:
			no = 1
		if no == 0:
			ans = [s1[0]]
			t = ans[0]
			while t != s1[1]:
				for j in range(26):
					if j != t and A[t][j] > 0:
						A[t][j] = 0
						A[j][t] = 0
						t = j
						ans.append(t)
						break
		if no == 1:
			print('NO')
		else:
			print('YES')
			E = [0] * 26
			for i in range(len(ans)):
				E[ans[i]] += 1
			for i in range(26):
				if E[i] == 0:
					ans.append(i)
			print(''.join([B[j] for j in 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')
for i in range(int(input())):
	s = input()
	ans = ''
	ans += s[0]
	t = 0
	for j in range(1, len(s)):
		if j == 1 and s[j] != s[0]:
			ans += s[j]
		if s[j] in ans:
			ind = ans.index(s[j])
			if ind == 0:
				if ans[1] != s[j - 1]:
					t = 1
					break
			elif ind == len(ans) - 1:
				if ans[-2] != s[j - 1]:
					t = 1
					break
			elif ans[ind - 1] != s[j - 1] and ans[ind + 1] != s[j - 1]:
				t = 1
				break
		if ans[0] != s[j - 1] and ans[-1] != s[j - 1] and (ans[ans.index(s[j - 1]) - 1] != s[j]) and (ans[ans.index(s[j - 1]) + 1] != s[j]):
			t = 1
			break
		elif ans[0] == s[j - 1] and ans[1] != s[j]:
			ans = s[j] + ans
		elif ans[-1] == s[j - 1] and ans[-2] != s[j]:
			ans = ans + s[j]
	if t == 1:
		print('NO')
	else:
		s = set(ans)
		alpha = [chr(x) for x in range(ord('a'), ord('z') + 1)]
		for i in alpha:
			if i not in s:
				ans += i
		print('YES')
		print(ans)


import collections
num = int(input())
for _ in range(num):
	s = input()
	key = ['' for i in range(100)]
	pos = 50
	keyset = set([chr(i) for i in range(97, 97 + 26)])
	mover = 1
	flag = True
	for x in s:
		if x in keyset:
			keyset.remove(x)
			if key[pos + mover] == '':
				pos += mover
			else:
				flag = False
				break
			key[pos] = x
		elif key[pos + 1] == x:
			mover = 1
			pos += mover
		elif key[pos - 1] == x:
			mover = -1
			pos += mover
		else:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')
		continue
	ans = [x for x in key if x != '']
	for x in list(keyset):
		ans.append(x)
	print(''.join(ans))


def main():
	import sys
	input = sys.stdin.readline
	for _ in range(int(input())):
		S = input().rstrip('\n')
		N = len(S)
		ans = {S[0]: 0}
		i2s = {0: S[0]}
		ok = 1
		off = 0
		for i in range(N - 1):
			(s, ss) = (S[i], S[i + 1])
			if ss not in ans:
				if (ans[s] + 1) % 26 not in i2s:
					ans[ss] = ans[s] + 1
					i2s[(ans[s] + 1) % 26] = ss
				elif (ans[s] - 1) % 26 not in i2s:
					ans[ss] = ans[s] - 1
					i2s[(ans[s] - 1) % 26] = ss
					off += 1
				else:
					ok = 0
					break
			else:
				if abs(ans[ss] - ans[s]) > 1:
					ok = 0
					break
				if ans[s] == 26 - off and ans[ss] == ans[s] - 1:
					ok = 0
					break
				if ans[s] == 26 - off - 1 and ans[ss] == ans[s] + 1:
					ok = 0
					break
		if ok:
			print('YES')
			ret = [''] * 26
			not_used = []
			for s in 'qwertyuiopasdfghjklzxcvbnm':
				if s in ans:
					ret[ans[s] + off] = s
				else:
					not_used.append(s)
			i = 0
			for s in not_used:
				while ret[i] != '':
					i += 1
				ret[i] = s
			print(''.join(ret))
		else:
			print('NO')
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math 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))
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 graph(vertex):
	return [[] for i in range(0, vertex + 1)]

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

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

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

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

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

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 bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def sieve(a):
	for i in range(3, 10 ** 6 + 1, 2):
		a[i] = 1
	for i in range(3, 10 ** 6 + 1, 2):
		for j in range(i * i, 10 ** 6 + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def bfs(g, st):
	visited = [0] * len(g)
	visited[st] = 1
	queue = []
	queue.append(st)
	new = []
	while len(queue) != 0:
		s = queue.pop()
		new.append(s)
		for i in g[s]:
			if visited[i] == 0:
				visited[i] = 1
				queue.append(i)
	return new

def solve():
	s = list(inp())
	n = len(s)
	for i in range(0, n):
		s[i] = ord(s[i]) - 96
	g = [[] for i in range(27)]
	for i in range(0, n - 1):
		if s[i + 1] not in g[s[i]]:
			g[s[i]].append(s[i + 1])
		if s[i] not in g[s[i + 1]]:
			g[s[i + 1]].append(s[i])
	for i in range(1, 27):
		if len(g[i]) > 2:
			print('NO')
			return
	ans = bfs(g, s[0])
	if len(g[ans[0]]) == 2:
		if ans[1] == g[ans[0]][0]:
			ind = ans.index(g[ans[0]][1])
			ans = ans[ind:][::-1] + ans[:ind]
		else:
			ind = ans.index(g[ans[0]][0])
			ans = ans[ind:][::-1] + ans[:ind]
	if n == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		return
	for i in range(len(ans)):
		if i == 0:
			if len(g[ans[i]]) == 2 or len(g[ans[i]]) == 0:
				print('NO')
				return
			elif ans[i + 1] != g[ans[i]][0]:
				print('NO')
				return
			continue
		if i == len(ans) - 1:
			if len(g[ans[i]]) == 2 or len(g[ans[i]]) == 0:
				print('NO')
				return
			elif ans[i - 1] != g[ans[i]][0]:
				print('NO')
				return
			continue
		if len(g[ans[i]]) != 2:
			print('NO')
			return
		elif ans[i - 1] not in g[ans[i]] or ans[i + 1] not in g[ans[i]]:
			print('NO')
			return
	for i in range(1, 27):
		if i not in ans:
			ans.append(i)
	lol = ''
	for i in range(0, len(ans)):
		lol += chr(ans[i] + 96)
	print('YES')
	print(lol)
testcase(int(inp()))


import sys
inp = sys.stdin.readline
input = lambda : inp().strip()
flush = sys.stdout.flush

def iin():
	return int(input())

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

def main():
	T = iin()
	while T:
		T -= 1
		s = list(input())
		L = len(s)
		done = 0
		sol = [s[0]]
		pt = 0
		l = 1
		for i in range(1, L):
			if s[i] not in sol:
				if 0 < pt < l - 1:
					done = 1
					break
				else:
					if pt == l - 1:
						sol.append(s[i])
						pt += 1
					elif pt == 0:
						sol = [s[i]] + sol
						pt = 0
					else:
						done = 1
						break
					l += 1
			elif pt < l - 1 and sol[pt + 1] == s[i]:
				pt += 1
			elif pt > 0 and sol[pt - 1] == s[i]:
				pt -= 1
			else:
				done = 1
				break
		if done:
			print('NO')
		else:
			ans = [chr(i + 97) for i in range(26) if chr(i + 97) not in sol]
			print('YES')
			print(''.join(sol + ans))
main()


INF = 10 ** 10

def main():
	print = out.append
	st = list(input())
	keyboard = []
	if len(set(st)) > 1:
		adj = defaultdict(set)
		for i in range(len(st) - 1):
			adj[st[i]].add(st[i + 1])
			adj[st[i + 1]].add(st[i])
		c1 = 0
		start = 'a'
		for i in adj:
			if len(adj[i]) > 2:
				print('NO')
				return
			elif len(adj[i]) == 1:
				c1 += 1
				start = i
		if c1 != 2:
			print('NO')
			return

		def dfs(root):
			keyboard.append(root)
			for i in adj[root]:
				if i not in keyboard:
					dfs(i)
		dfs(start)
		if len(keyboard) != len(set(st)):
			print('NO')
			return
	for i in range(26):
		s = chr(ord('a') + i)
		if s not in keyboard:
			keyboard.append(s)
	print('YES')
	print(''.join(keyboard))
import sys
from collections import defaultdict, Counter
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]
print(*out, sep='\n')


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')
for _ in range(int(input())):
	s = input()
	ans = s[0]
	current = 1
	pos = True
	for i in range(1, len(s)):
		next = s[i]
		if next not in ans:
			if current == len(ans):
				ans += next
				current += 1
			elif current != 1:
				pos = False
				break
			else:
				ans = next + ans
		elif ans.find(next) == current - 2:
			current -= 1
		elif ans.find(next) == current:
			current += 1
		else:
			pos = False
			break
	if not pos:
		print('NO')
	else:
		print('YES')
		all = 'abcdefghijklmnopqrstuvwxyz'
		print(ans + ''.join((k for k in all if k not in ans)))


from collections import *

def out(node):
	print('YES')
	nxt = graph[node][0] if graph[node] != [] else node
	s = list('abcdefghijklmnopqrstuvwxyz')
	s.remove(node)
	fin = [node]
	if nxt != node:
		graph[nxt].remove(node)
		s.remove(nxt)
		fin.append(nxt)
	while graph[nxt]:
		nxt = graph[fin[-1]][0]
		graph[nxt].remove(fin[-1])
		fin.append(nxt)
		s.remove(nxt)
	print(''.join(fin + s))
for _ in range(int(input())):
	strin = list(input())
	graph = defaultdict(list)
	degree = defaultdict(int)
	if len(strin) == 1:
		out(strin[0])
		continue
	for i in range(len(strin) - 1):
		(u, v) = (strin[i], strin[i + 1])
		if v in graph[u]:
			continue
		graph[u].append(v)
		graph[v].append(u)
		degree[v] += 1
		degree[u] += 1
	(node, ones, twos) = ('', 0, 0)
	for (i, j) in degree.items():
		if j == 1:
			ones += 1
			node = i
		elif j == 2:
			twos += 1
		else:
			node = ''
			break
	if node != '' and ones == 2:
		out(node)
	else:
		print('NO')


import sys
from math import log2, floor, ceil
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
for _ in range(int(ri())):
	dic2 = {}
	dic1 = {}
	st = ri()
	dic1[st[0]] = 0
	dic2[0] = st[0]
	flag = True
	for i in range(1, len(st)):
		ch = st[i]
		if st[i] == st[i - 1]:
			flag = False
			break
		if st[i] not in dic1:
			pos = dic1[st[i - 1]]
			if pos + 1 in dic2 and dic2[pos + 1] == st[i]:
				continue
			elif pos - 1 in dic2 and dic2[pos - 1] == st[i]:
				continue
			if pos + 1 not in dic2:
				dic1[st[i]] = pos + 1
				dic2[pos + 1] = st[i]
				continue
			elif pos - 1 not in dic2:
				dic1[st[i]] = pos - 1
				dic2[pos - 1] = st[i]
				continue
			else:
				flag = False
				break
		else:
			pos1 = dic1[st[i]]
			pos2 = dic1[st[i - 1]]
			if abs(pos1 - pos2) > 1:
				flag = False
				break
	if not flag:
		NO()
	else:
		YES()
		minn = min([dic1[i] for i in dic1])
		ans = [-1] * 26
		for i in dic2:
			ans[i + abs(minn)] = dic2[i]
		ite = 25
		for i in range(25, -1, -1):
			if chr(ord('a') + i) not in dic1:
				ans[ite] = chr(ord('a') + i)
				dic1[chr(ord('a') + i)] = ite
				ite -= 1
		print(''.join(ans))


def solve(s):
	res = [s[0]]
	i = 0
	for c in s[1:]:
		if 0 <= i + 1 < len(res) and res[i + 1] == c:
			i += 1
		elif 0 <= i - 1 < len(res) and res[i - 1] == c:
			i -= 1
		elif i == 0 and c not in res:
			res.insert(0, c)
		elif i == len(res) - 1 and c not in res:
			res.append(c)
			i += 1
		else:
			return None
	for c in 'abcdefghijklmnopqrstuvwxyz':
		if c not in res:
			res.append(c)
	return ''.join(res)
t = int(input())
for _ in range(t):
	ans = solve(input())
	if ans == None:
		print('NO')
	else:
		print('YES')
		print(ans)


import sys
sys.setrecursionlimit(10 ** 8)

def dfs(edges, node, visited, parent):
	visited.add(node)
	for kid in edges[node]:
		if kid not in visited:
			if dfs(edges, kid, visited, node):
				return True
		elif parent != kid:
			return True
	return False

def cycle(edges):
	visited = set()
	for i in edges.keys():
		if i not in visited:
			if dfs(edges, i, visited, -1):
				return True
	return False

def solve(s, ans):
	edges = {}
	if len(s) == 1:
		arr = ['YES']
		order = ''
		for i in range(26):
			order += chr(ord('a') + i)
		arr.append(order)
		ans.append(arr)
		return
	for i in range(len(s) - 1):
		a = s[i]
		b = s[i + 1]
		if a not in edges.keys():
			edges[a] = set()
		if b not in edges.keys():
			edges[b] = set()
		edges[a].add(b)
		edges[b].add(a)
	if cycle(edges):
		ans.append(['NO'])
		return
	for i in edges.keys():
		if len(edges[i]) > 2:
			ans.append(['NO'])
			return
	arr = ['YES']
	for i in edges.keys():
		if len(edges[i]) == 1:
			leaf = i
			break
	visited = set()
	order = ''
	stack = [leaf]
	while stack:
		curr = stack.pop()
		if curr not in visited:
			visited.add(curr)
			order += curr
			for kid in edges[curr]:
				stack.append(kid)
	for i in range(26):
		if chr(ord('a') + i) not in visited:
			order += chr(ord('a') + i)
	arr.append(order)
	ans.append(arr)

def main():
	ans = []
	t = int(input())
	for i in range(t):
		s = input()
		solve(s, ans)
	for i in ans:
		for j in i:
			print(j)
main()


import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
for _ in range(N):
	s = list(input())[:-1]
	a = ord('a')
	e = dd(set)
	for i in range(len(s) - 1):
		e[s[i]].add(s[i + 1])
		e[s[i + 1]].add(s[i])
	x = '?'
	for k in e.keys():
		if len(e[k]) > 2:
			x = '?'
			break
		if len(e[k]) == 1:
			x = k
	if x == '?' and len(s) > 1:
		print('NO')
		continue
	elif x == '?':
		x = s[0]
	res = []
	vis = set()
	sta = [x]
	while len(sta):
		p = sta.pop()
		res.append(p)
		vis.add(p)
		for q in e[p]:
			if q in vis:
				continue
			sta.append(q)
	print('YES')
	for i in range(26):
		if chr(i + a) in res:
			continue
		res.append(chr(i + a))
	print(''.join(res))


for _ in range(int(input())):
	pas = input()
	alpha = 'abcdefghijklmnopqrstuvwxyz'
	l = pas[0]
	p = 0
	f = True
	for i in range(1, len(pas)):
		if p > 0 and pas[i] == l[p - 1]:
			p -= 1
		elif p < len(l) - 1 and pas[i] == l[p + 1]:
			p += 1
		elif p == len(l) - 1 and pas[i] not in l:
			p += 1
			l += pas[i]
		elif p == 0 and pas[i] not in l:
			l = pas[i] + l
		else:
			f = False
			break
	for i in alpha:
		if i not in l:
			l += i
	if f:
		print('YES\n' + l)
	else:
		print('NO')


alp = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
for (s, i) in enumerate(alp):
	dic[i] = s
t = int(input())
for loop in range(t):
	s = input()
	ans = []
	lis = [None] * 100
	ap = [None] * 26
	flag = True
	for (i, S) in enumerate(s):
		if i == 0:
			Snum = dic[S]
			lis[50] = Snum
			ap[Snum] = 50
		else:
			Snum = dic[S]
			BS = dic[s[i - 1]]
			if ap[Snum] == None:
				if lis[ap[BS] - 1] == None:
					lis[ap[BS] - 1] = Snum
					ap[Snum] = ap[BS] - 1
				elif lis[ap[BS] + 1] == None:
					lis[ap[BS] + 1] = Snum
					ap[Snum] = ap[BS] + 1
				else:
					flag = False
					break
			elif abs(ap[Snum] - ap[BS]) != 1:
				flag = False
				break
	if flag:
		print('YES')
		anslis = []
		for i in range(26):
			if ap[i] == None:
				anslis.append([float('inf'), alp[i]])
			else:
				anslis.append([ap[i], alp[i]])
		anslis.sort()
		ans = []
		for i in range(26):
			ans.append(anslis[i][1])
		print(''.join(ans))
	else:
		print('NO')


def get_adjecent_chars(password, find_char):
	adjecent_index = [(i - 1, i + 1) for i in range(len(password)) if find_char == password[i]]
	final = set()
	for (i, j) in adjecent_index:
		if 0 <= i < len(password):
			final.add(password[i])
		if 0 <= j < len(password):
			final.add(password[j])
	return [i for i in final]

def create_chars_dict(s):
	s_list = set([char for char in s])
	impossible = False
	s_dict = {}
	extreme_counter = 0
	extremes = []
	for i in s_list:
		chars = get_adjecent_chars(s, i)
		if len(chars) > 2:
			impossible = True
			break
		if len(chars) == 1:
			extreme_counter += 1
			extremes.append(i)
		s_dict[i] = chars
	if extreme_counter != 2 and len(s) > 1:
		impossible = True
	return (s_dict, extremes, impossible)

def optimize_key_order(s_dict, extremes):
	current_string = extremes[0] + s_dict[extremes[0]][0]
	b_previous = current_string[-2]
	previous = current_string[-1]
	while previous != extremes[1]:
		(i, j) = s_dict[previous]
		p = i if i != b_previous else j
		current_string += p
		b_previous = current_string[-2]
		previous = current_string[-1]
	return current_string

def build_keyboard(default_keyboard, important_sequence):
	for i in important_sequence:
		default_keyboard = default_keyboard.replace(i, '')
	return important_sequence + default_keyboard
for i in range(int(input())):
	s = input()
	default_keyboard = 'abcdefghijklmnopqrstuvwxyz'
	(s_dict, extremes, impossible) = create_chars_dict(s)
	if impossible:
		print('NO')
		continue
	if len(s) == 1:
		print('YES')
		print(build_keyboard(default_keyboard, s))
		continue
	current_string = optimize_key_order(s_dict, extremes)
	print('YES')
	print(build_keyboard(default_keyboard, current_string))


q = int(input())
while q:
	q += -1
	s = input()
	ans = []
	vis = [0] * 26
	c = 1
	for i in range(len(s) - 1):
		t1 = ord(s[i]) - 97
		t2 = ord(s[i + 1]) - 97
		if vis[t1] == 1 and vis[t2] == 1:
			ch = 0
			for ii in range(len(ans) - 1):
				if ans[ii] == s[i] and ans[ii + 1] == s[i + 1] or (ans[ii] == s[i + 1] and ans[ii + 1] == s[i]):
					ch = 1
					break
			if ch == 0:
				c = 0
				break
		elif vis[t1] == 1 and vis[t2] == 0:
			if ans[0] == s[i]:
				ans.insert(0, s[i + 1])
			elif ans[len(ans) - 1] == s[i]:
				ans.append(s[i + 1])
			else:
				c = 0
				break
		elif vis[t1] == 0 and vis[t2] == 1:
			if ans[0] == s[i + 1]:
				ans.insert(0, s[i])
			elif ans[len(ans) - 1] == s[i + 1]:
				ans.append(s[i])
			else:
				c = 0
				break
		else:
			if len(ans) != 0:
				ans.append(' ')
			ans.append(s[i])
			ans.append(s[i + 1])
		vis[t1] = 1
		vis[t2] = 1
	if c:
		print('YES')
		for i in ans:
			if i != ' ':
				print(i, end='')
		for i in range(26):
			if vis[i] == 0:
				print(chr(i + 97), end='')
		print()
	else:
		print('NO')


def dfs(v, vis, comp):
	vis[v] = True
	comp.append(v)
	for u in adj[v]:
		if not vis[u]:
			dfs(u, vis, comp)
for tt in range(int(input())):
	s = input()
	n = len(s)
	a = [ord(s[i]) - 97 for i in range(n)]
	adj = [set() for i in range(26)]
	for i in range(n - 1):
		adj[a[i]].add(a[i + 1])
		adj[a[i + 1]].add(a[i])
	vis = [False] * 26
	comp = []
	dfs(a[0], vis, comp)
	mx = 0
	one = []
	for i in comp:
		mx = max(mx, len(adj[i]))
		if len(adj[i]) == 1 or len(adj[i]) == 0:
			one.append(i)
	if mx > 2 or len(one) < 1:
		print('NO')
		continue
	comp = []
	vis = [False] * 26
	dfs(one[0], vis, comp)
	ans = ''
	for i in comp:
		ans += chr(i + 97)
	for i in range(26):
		if chr(i + 97) not in ans:
			ans += chr(i + 97)
	print('YES')
	print(ans)


t = int(input())
a = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(t):
	alphcp = list(a)
	s = input()
	ret = [s[0]]
	used = [s[0]]
	alphcp.remove(s[0])
	f = True
	for i in range(1, len(s)):
		if s[i] in used:
			fl = True
			for j in range(len(ret)):
				if ret[j] == s[i]:
					if j == 0 and ret[j + 1] == s[i - 1]:
						pass
					elif j == len(ret) - 1 and ret[j - 1] == s[i - 1]:
						pass
					elif j == 0 or j == len(ret) - 1:
						print('NO')
						f = False
						fl = False
						break
					elif ret[j - 1] == s[i - 1] or ret[j + 1] == s[i - 1]:
						pass
					else:
						print('NO')
						f = False
						fl = False
						break
			if not fl:
				break
		else:
			used.append(s[i])
			alphcp.remove(s[i])
			if ret[0] == s[i - 1]:
				ret.insert(0, s[i])
			elif ret[-1] == s[i - 1]:
				ret.append(s[i])
			else:
				print('NO')
				f = False
				break
	if f:
		ret += alphcp
		xd = ''.join(ret)
		print('YES')
		print(xd)


T = int(input())
while T > 0:
	s = input()
	neighbors = [[] for i in range(26)]
	for i in range(len(s)):
		if i - 1 >= 0:
			x = ord(s[i - 1]) - ord('a')
			if x not in neighbors[ord(s[i]) - ord('a')]:
				neighbors[ord(s[i]) - ord('a')].append(x)
		if i + 1 < len(s):
			x = ord(s[i + 1]) - ord('a')
			if x not in neighbors[ord(s[i]) - ord('a')]:
				neighbors[ord(s[i]) - ord('a')].append(x)
	tail = 0
	exist = True
	start = -1
	mid = 0
	for i in range(26):
		if len(neighbors[i]) == 1:
			tail += 1
			start = i
		if len(neighbors[i]) == 2:
			mid += 1
		if len(neighbors[i]) > 2:
			exist = False
			break
	if exist is False or tail == 1:
		print('NO')
	elif tail == 0:
		if mid > 0:
			print('NO')
		else:
			res = []
			for i in range(26):
				res.append(chr(ord('a') + i))
			print('YES')
			print(''.join(res))
	else:
		res = []
		res.append(chr(ord('a') + start))
		index = neighbors[start][0]
		prev = start
		while len(neighbors[index]) != 1:
			res.append(chr(ord('a') + index))
			for x in neighbors[index]:
				if x != prev:
					prev = index
					index = x
					break
		res.append(chr(ord('a') + index))
		for i in range(26):
			if len(neighbors[i]) == 0:
				res.append(chr(ord('a') + i))
		print('YES')
		print(''.join(res))
	T -= 1


def solve():
	s = input()
	c = s[0]
	s = s[1:]
	last = 0
	used = {}
	for i in s:
		used[c[last]] = 1
		if last + 1 != len(c):
			if c[last + 1] == i:
				last += 1
				continue
		if last:
			if c[last - 1] == i:
				last -= 1
				continue
		if used.get(i, 0) == 1:
			print('NO')
			return
		if last + 1 == len(c):
			last += 1
			c += i
			continue
		if last == 0:
			c = i + c
			continue
		print('NO')
		return
	used[c[last]] = 1
	for i in range(26):
		if used.get(chr(ord('a') + i), 0) == 0:
			c += chr(ord('a') + i)
	print('YES')
	print(c)
for i in range(int(input())):
	solve()


def solve_c():
	n = int(input())
	for _ in range(n):
		c()

def c():
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	s = input()
	n = len(s)
	deja_vu = {s[0]}
	r = 0
	l = s[0]
	len_l = 1
	for x in s[1:]:
		if x in deja_vu:
			if l[r] == x:
				continue
			elif r - 1 >= 0 and l[r - 1] == x:
				r -= 1
				continue
			elif r + 1 < len_l and l[r + 1] == x:
				r += 1
				continue
			else:
				print('NO')
				return
		else:
			if r == len(l) - 1:
				l += x
				r += 1
				len_l += 1
			elif r == 0:
				l = x + l
				len_l += 1
			else:
				print('NO')
				return
			deja_vu.add(x)
	print('YES')
	l = l + ''.join([x for x in alphabet if x not in deja_vu])
	print(l)
solve_c()


import collections, heapq

def main():
	T = int(input().strip())
	for _ in range(T):
		s = input().strip()
		d = collections.defaultdict(set)
		for i in range(len(s) - 1):
			d[s[i]].add(s[i + 1])
			d[s[i + 1]].add(s[i])
		impossible = False
		stack = []
		res = []
		unseen = set()
		for i in range(26):
			unseen.add(chr(ord('a') + i))
		for x in unseen:
			if len(d[x]) < 2:
				stack.append(x)
				res.append(x)
				unseen.remove(x)
				break
		while unseen:
			while stack:
				if impossible:
					break
				cur = stack.pop()
				for c in d[cur]:
					if impossible:
						break
					if c in unseen:
						stack.append(c)
						if cur == res[-1]:
							res.append(c)
						else:
							impossible = True
						unseen.remove(c)
					else:
						for c_idx in range(len(res)):
							if res[c_idx] == c:
								break
						if not (c_idx > 0 and res[c_idx - 1] == cur or (c_idx < len(res) - 1 and res[c_idx + 1] == cur)):
							impossible = True
			if impossible:
				break
			nextChr = None
			for x in unseen:
				if len(d[x]) < 2:
					nextChr = x
					break
			if unseen and (not nextChr):
				impossible = True
			if nextChr:
				res.append(nextChr)
				stack.append(nextChr)
				unseen.remove(nextChr)
		if impossible:
			print('NO')
		else:
			print('YES')
			print(''.join(res))
main()


import sys
input = sys.stdin.readline
from math import log2, log, ceil

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

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

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

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

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

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

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

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

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

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

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

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

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	string = input().strip()
	f = 1
	dick = {}
	c = 0
	mset = set()
	for i in string:
		if dick.get(c - 1) == i and i in mset:
			c -= 1
		elif dick.get(c + 1) == i and i in mset:
			c += 1
		elif c + 1 not in dick and i not in mset:
			c += 1
			dick[c] = i
			mset.add(i)
		elif c - 1 not in dick and i not in mset:
			c -= 1
			dick[c] = i
			mset.add(i)
		else:
			f = 0
			break
	if not f:
		print('NO')
	else:
		this = min(list(dick.keys()))
		if this <= 0:
			this = abs(this)
		else:
			this = -this
		ans = [0] * 26
		for i in dick:
			ans[i + this] = dick[i]
		alps = set([chr(i) for i in range(97, 97 + 26)])
		alps = alps.difference(mset)
		while ans and ans[-1] == 0:
			ans.pop()
		ans = ans + list(alps)
		print('YES')
		print(''.join(ans))


t = int(input())

def c(g):
	return ord(g) - ord('a')

def az(i):
	return chr(ord('a') + i)

def dfs():
	i = adn.index(1)
	q = [i]
	ans = ''
	pa = [-1 for i in range(26)]
	while q:
		x = q.pop()
		ans += az(x)
		for y in adj[x]:
			if y == pa[x]:
				continue
			q.append(y)
			pa[y] = x
	return ans
for _ in range(t):
	s = str(input())
	n = len(s)
	adn = [0 for i in range(26)]
	adj = [set() for i in range(26)]
	for i in range(1, n - 1):
		o = c(s[i])
		adj[o].add(c(s[i - 1]))
		adj[o].add(c(s[i + 1]))
	if n > 1:
		adj[c(s[0])].add(c(s[1]))
		adj[c(s[-1])].add(c(s[-2]))
	for i in range(26):
		adn[i] = len(adj[i])
	if adn == [0] * 26:
		print('YES')
		print(''.join([az(i) for i in range(26)]))
		continue
	if adn.count(1) != 2 or 3 in adn or 1 not in adn:
		print('NO')
		continue
	ans = dfs()
	for i in range(26):
		if adn[i] == 0:
			ans += az(i)
	print('YES')
	print(ans)


import math
for T in range(int(input().strip())):
	s = input().strip()
	val = True
	curr = 0
	a = s[0]
	b = {chr(ord('a') + i) for i in range(26)}
	b.remove(a[0])
	for i in range(len(s)):
		if s[i] == a[curr]:
			val = True
		elif curr - 1 >= 0 and a[curr - 1] == s[i]:
			curr = curr - 1
		elif curr + 1 < len(a) and a[curr + 1] == s[i]:
			curr = curr + 1
		elif curr == 0 and s[i] in b:
			a = ''.join(list(a)[::-1])
			a += s[i]
			a = ''.join(list(a)[::-1])
			b.remove(s[i])
		elif curr == len(a) - 1 and s[i] in b:
			a += s[i]
			curr = curr + 1
			b.remove(s[i])
		else:
			val = False
			break
	if not val:
		print('NO')
		continue
	print('YES')
	for i in a:
		print(i, end='')
	for i in b:
		print(i, end='')
	print('')


t = int(input())
for i in range(t):
	s = input()
	a = 'abcdefghijklmnopqrstuvwxyz'
	s1 = s[0]
	counter = 0
	fl = True
	for j in range(1, len(s)):
		ind = s1.index(s[j - 1])
		if s1.count(s[j]) == 0:
			if ind == 0:
				s1 = s[j] + s1
				counter += 1
			elif ind == counter:
				s1 = s1 + s[j]
				counter += 1
			else:
				print('NO')
				fl = False
				break
		else:
			ind2 = s1.index(s[j])
			if abs(ind2 - ind) == 1:
				pass
			else:
				print('NO')
				fl = False
				break
	if fl:
		for item in s1:
			a = a.replace(item, '')
		s1 = s1 + a
		print('YES')
		print(s1)


import string

def solve(s):
	found = set()
	layout = ''
	ptr = -1
	for c in s:
		if len(layout) < 2:
			layout += c
			ptr = len(layout) - 1
			found.add(c)
		elif ptr > 0 and layout[ptr - 1] == c:
			ptr = ptr - 1
		elif ptr < len(layout) - 1 and layout[ptr + 1] == c:
			ptr = ptr + 1
		elif ptr == 0 and c not in found:
			layout = c + layout
			found.add(c)
		elif ptr == len(layout) - 1 and c not in found:
			layout += c
			ptr += 1
			found.add(c)
		else:
			print('NO')
			return
	for c in string.ascii_lowercase:
		if c not in found:
			layout += c
	print('YES')
	print(layout)
t = int(input())
for _ in range(t):
	solve(input())


def key_layout(s):
	letters = {chr(i): set([]) for i in range(97, 97 + 26)}
	for i in range(len(s)):
		if i > 0:
			letters[s[i - 1]].add(s[i])
			letters[s[i]].add(s[i - 1])
	if any((len(letters[let]) > 2 for let in letters)):
		return 'NO'
	visited = set([])
	order = []
	f1s = list(filter(lambda x: len(letters[x]) == 1, letters))
	for x in f1s:
		if x in visited:
			continue
		visited.add(x)
		cur = x
		order_here = [cur]
		while cur == x or len(letters[cur]) > 1:
			for n in letters[cur]:
				if n not in visited:
					visited.add(n)
					cur = n
					order_here.append(n)
		order.append(''.join(order_here))
	if len(list(filter(lambda x: len(letters[x]) == 2 and x not in visited, letters))) > 0:
		return 'NO'
	order.append(''.join(filter(lambda x: len(letters[x]) == 0, letters)))
	print('YES')
	return ''.join(order)
n = int(input())
for i in range(n):
	print(key_layout(input()))


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	s = st()
	curr = currpo = 0
	d = {}
	visited = {}
	ans = 'YES'
	for i in s:
		if i in d:
			if d[i] == currpo - 1:
				currpo -= 1
			elif d[i] == currpo + 1:
				currpo += 1
			else:
				ans = 'NO'
				break
		elif currpo not in visited:
			d[i] = currpo
			visited[currpo] = 1
		elif currpo - 1 not in visited:
			currpo -= 1
			d[i] = currpo
			visited[currpo] = 1
		elif currpo + 1 not in visited:
			currpo += 1
			d[i] = currpo
			visited[currpo] = 1
		else:
			ans = 'NO'
			break
	print(ans)
	if ans[0] == 'Y':
		s = ''.join((str(e) for e in sorted(list(d), key=lambda x: d[x])))
		for i in 'abcdefghijklmnopqrstuvwxyz':
			if i not in s:
				s += i
		print(s)


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

def main():
	global alp1
	s = input()
	klav = s[0]
	alp = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0}
	pos = 0
	alp[s[0]] = 1
	for j in range(1, len(s)):
		if alp[s[j]] > 0:
			if pos == 0:
				if klav[1] != s[j]:
					return 'NO'
				pos = 1
			elif pos == len(klav) - 1:
				if klav[-2] != s[j]:
					return 'NO'
				pos = len(klav) - 2
			elif klav[pos + 1] != s[j] and klav[pos - 1] != s[j]:
				return 'NO'
			elif klav[pos + 1] == s[j]:
				pos += 1
			else:
				pos -= 1
		elif klav[0] == s[j - 1]:
			klav = s[j] + klav
			pos = 0
			alp[s[j]] += 1
		elif klav[-1] == s[j - 1]:
			pos = len(klav)
			klav += s[j]
			alp[s[j]] += 1
		else:
			return 'NO'
	print('YES')
	for j in range(26):
		if alp[alp1[j]] == 0:
			klav += alp1[j]
	return klav
alp1 = ['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']
for i in range(int(input())):
	print(main())


def solve():
	password = input()
	pos = [None] * 26
	idx = 27
	keyboard = [None] * (26 * 2 + 1)
	sol = True
	for p in password:
		i = ord(p) - ord('a')
		if pos[i] is None:
			if keyboard[idx - 1] is None:
				idx -= 1
			elif keyboard[idx + 1] is None:
				idx += 1
			else:
				sol = False
				break
			pos[i] = idx
		elif abs(pos[i] - idx) <= 1:
			idx = pos[i]
		else:
			sol = False
		keyboard[idx] = p
	keyboard_str = ''
	for i in keyboard:
		if i is not None:
			keyboard_str += i
	for (i, p) in enumerate(pos):
		if p is None:
			keyboard_str += chr(i + ord('a'))
	if sol:
		print('YES')
		print(keyboard_str)
	else:
		print('NO')

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


T = int(input())

def solve(s):
	kb = list()
	cursor = -1
	seen = set()
	for c in s:
		if c in seen:
			if cursor - 1 >= 0 and kb[cursor - 1] == c:
				cursor -= 1
			elif cursor + 1 < len(kb) and kb[cursor + 1] == c:
				cursor += 1
			else:
				print('NO')
				return
		else:
			if cursor not in [0, len(kb) - 1]:
				print('NO')
				return
			elif cursor == 0:
				kb.insert(0, c)
				cursor = 0
			else:
				kb.append(c)
				cursor = len(kb) - 1
			seen.add(c)
	print('YES')
	ans = ''.join(kb)
	for c in 'abcdefghijklmnopqrstuvwxyz':
		if c not in seen:
			ans += c
	print(ans)
for _ in range(T):
	solve(input())


def dfs(e, v, res, done):
	res.append(v)
	done.add(v)
	for u in e[v]:
		if u not in done:
			dfs(e, u, res, done)

def go():
	s = input()
	if len(s) == 1:
		return (True, 'bacdefghijklmnopqrstuvwxyz')
	e = {ss: set() for ss in s}
	d = {}
	for i in range(len(s) - 1):
		(a, b) = (s[i], s[i + 1])
		if a not in e[b]:
			e[a].add(b)
			e[b].add(a)
			d[a] = d.get(a, 0) + 1
			d[b] = d.get(b, 0) + 1
	one = False
	start = None
	two = False
	for (a, dd) in d.items():
		if dd > 2:
			return (False, '')
		if dd == 2:
			two = True
		if dd == 1:
			one = True
			start = a
	if two and (not one):
		return (False, '')
	res = []
	done = set()
	dfs(e, start, res, done)
	alph = set('bacdefghijklmnopqrstuvwxyz')
	ans = ''.join(res) + ''.join(alph - set(res))
	return (True, ans)
t = int(input())
for _ in range(t):
	(res, ans) = go()
	if res:
		print('YES')
		print(ans)
	else:
		print('NO')


def dfs(x, ans, vis, g):
	ans.append(x)
	vis[x] = True
	for i in g[x]:
		if not vis[i]:
			dfs(i, ans, vis, g)

def solve(s):
	g = [[] for i in range(26)]
	vis = [False] * 26
	for i in range(len(s) - 1):
		if s[i + 1] not in g[s[i]] and s[i] not in g[s[i + 1]]:
			g[s[i]].append(s[i + 1])
			g[s[i + 1]].append(s[i])
	for i in range(26):
		if len(g[i]) > 2:
			print('NO')
			return
	ans = []
	for i in range(26):
		if not vis[i] and len(g[i]) < 2:
			dfs(i, ans, vis, g)
	for i in range(26):
		if not vis[i]:
			print('NO')
			return
	print('YES')
	print(''.join([chr(i + ord('a')) for i in ans]))
	return
for _ in range(int(input())):
	s = list(map(lambda x: ord(x) - ord('a'), list(input())))
	solve(s)


t = int(input())
for _ in range(t):
	s = input()
	l = len(s)
	if l == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	peer = [set() for _ in range(26)]
	for i in range(1, l):
		(a, b) = (ord(s[i - 1]) - 97, ord(s[i]) - 97)
		peer[a].add(b)
		peer[b].add(a)
		if len(peer[a]) > 2 or len(peer[b]) > 2:
			print('NO')
			break
	else:
		for i in range(26):
			if len(peer[i]) == 1:
				st = i
				break
		else:
			print('NO')
			continue
		used = [0 for _ in range(26)]
		used[st] = 1
		ans = [st]
		now = [st]
		while now:
			last = now
			now = []
			for x in last:
				for y in peer[x]:
					if used[y] == 0:
						used[y] = 1
						now.append(y)
						ans.append(y)
			if now == []:
				break
		ans2 = ''
		for x in ans:
			ans2 += chr(x + 97)
		for i in range(26):
			if used[i] == 0:
				ans2 += chr(i + 97)
		print('YES')
		print(ans2)


def checker(s):
	(ind, flag, res) = (0, 0, '')
	for j in range(len(s)):
		if not s[j] in res:
			if len(res) - 1 == ind:
				res += s[j]
				ind = len(res) - 1
			elif ind == 0:
				res = s[j] + res
			else:
				flag = 1
				break
		elif ind - 1 >= 0 and res[ind - 1] == s[j]:
			ind -= 1
		elif ind + 1 < len(res) and res[ind + 1] == s[j]:
			ind += 1
		else:
			flag = 1
			break
	if flag:
		return ('NO',)
	else:
		for j in range(ord('a'), ord('z') + 1):
			if not chr(j) in res:
				res += chr(j)
		return ('YES', res)
for _ in range(int(input())):
	t = input()
	print(*checker(t), sep='\n')


from collections import deque
t = int(input())
for i2 in range(t):
	x = str(input())
	d = deque()
	(now, no) = (-1, 0)
	for i in range(len(x)):
		if now > 0 and d[now - 1] == x[i]:
			now -= 1
		elif now + 1 < len(d) and d[now + 1] == x[i]:
			now += 1
		elif now == len(d) - 1 and x[i] not in d:
			d.append(x[i])
			now += 1
		elif now == 0 and x[i] not in d:
			d.appendleft(x[i])
		else:
			no = 1
			break
		if len(d) > 26:
			no = 1
			break
	if no == 1:
		print('NO')
	else:
		print('YES')
		for i in range(len(d)):
			print(d[i], end='')
		for i in range(26):
			if chr(i + 97) not in d:
				print(chr(i + 97), end='')
		print('')


def cycledetected(root):
	stack = [root]
	vis = [0] * 26
	while len(stack) != 0:
		element = stack.pop()
		vis[element] = 1
		flag = 0
		for i in graph[element]:
			if vis[i] == 1 and flag:
				return True
			elif vis[i] == 1 and (not flag):
				flag = 1
			else:
				stack.append(i)
	return False
for nt in range(int(input())):
	s = input()
	n = len(s)
	if n == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	if n == 2:
		print('YES')
		ans = s
		for i in range(97, 123):
			if chr(i) not in ans:
				ans += chr(i)
		print(ans)
		continue
	graph = [[] for i in range(26)]
	curr = ord(s[0]) - 97
	ans = 'YES'
	for i in range(1, n):
		if ord(s[i]) - 97 in graph[curr]:
			curr = ord(s[i]) - 97
		elif ord(s[i]) - 97 not in graph[curr]:
			if len(graph[curr]) >= 2:
				ans = 'NO'
				break
			else:
				graph[curr].append(ord(s[i]) - 97)
				graph[ord(s[i]) - 97].append(curr)
				curr = ord(s[i]) - 97
	if ans == 'NO':
		print(ans)
		continue
	root = -1
	for i in range(26):
		if len(graph[i]) == 1:
			root = i
			break
	if root == -1:
		root = ord(s[0]) - 97
	if cycledetected(root):
		print('NO')
		continue
	print('YES')
	stack = [root]
	ans = chr(root + 97)
	vis = [0] * 26
	while len(stack) != 0:
		element = stack.pop()
		vis[element] = 1
		for i in graph[element]:
			if vis[i] == 0:
				stack.append(i)
				ans += chr(i + 97)
	for i in range(97, 123):
		if chr(i) not in ans:
			ans += chr(i)
	print(ans)


from collections import deque, defaultdict
t = int(input())
for i in range(t):
	s = list(str(input().rstrip()))
	deq = deque()
	d = defaultdict(int)
	cur = 0
	flag = True
	for c in s:
		if d[c] == 0:
			if cur == 0:
				deq.appendleft(c)
			elif cur == len(deq) - 1:
				deq.append(c)
				cur = len(deq) - 1
			else:
				flag = False
				break
			d[c] = 1
		elif cur == len(deq) - 1:
			if deq[cur - 1] == c:
				cur -= 1
			else:
				flag = False
				break
		elif cur == 0:
			if deq[cur + 1] == c:
				cur += 1
			else:
				flag = False
				break
		elif deq[cur + 1] == c:
			cur += 1
		elif deq[cur - 1] == c:
			cur -= 1
		else:
			flag = False
			break
	for alph in list('abcdefghijklmnopqrstuvwxyz'):
		if d[alph] == 0:
			deq.append(alph)
	if not flag:
		print('NO')
	else:
		print('YES')
		print(''.join(list(map(str, deq))))


t = int(input())
while t:
	t -= 1
	s = input()
	key = ' ' + s[0] + ' '
	curr = 1
	flag = False
	for i in range(1, len(s)):
		if key.find(s[i]) != -1:
			if key[curr - 1] == s[i]:
				curr -= 1
			elif key[curr + 1] == s[i]:
				curr += 1
			else:
				flag = True
				break
		elif key[curr - 1] == ' ':
			key = ' ' + s[i] + key[1:]
		elif key[curr + 1] == ' ':
			key = key[:-1] + s[i] + ' '
			curr += 1
		else:
			flag = True
			break
	if flag:
		print('NO')
	else:
		print('YES')
		print(key[1:-1], end='')
		x = 'abcdefghijklmnopqrstuvwxyz'
		for i in x:
			if key.find(i) != -1:
				continue
			else:
				print(i, end='')
		print()


import string

def cal(s):
	for (a, b) in zip(s[:-1], s[1:]):
		if a == b:
			return 'NO'
	ans = s[0]
	i = 0
	found = {s[0]}
	for (a, b) in zip(s[:-1], s[1:]):
		if b in found:
			if i + 1 < len(ans) and ans[i + 1] == b:
				i += 1
			elif i - 1 >= 0 and ans[i - 1] == b:
				i -= 1
			else:
				return 'NO'
		elif i == len(ans) - 1:
			ans += b
			i += 1
		elif i == 0:
			ans = b + ans
		else:
			return 'NO'
		found.add(b)
	return 'YES\n' + ans + str(''.join(set(string.ascii_lowercase) - found))
T = int(input())
for _ in range(T):
	s = input()
	print(cal(s))


import sys
queries = int(sys.stdin.readline())
all_chars = [chr(code) for code in range(ord('a'), ord('z') + 1)]

def findIdealKeyboard(text):
	keyboard = ''
	letters = 0
	keyboard_pos = 0
	text_pos = 0
	while text_pos < len(text):
		symbol = text[text_pos]
		if not symbol in keyboard:
			if keyboard_pos == 0:
				keyboard = text[text_pos] + keyboard
			elif keyboard_pos == len(keyboard) - 1:
				keyboard += text[text_pos]
				keyboard_pos += 1
			else:
				return False
		elif keyboard_pos > 0 and symbol == keyboard[keyboard_pos - 1]:
			keyboard_pos -= 1
		elif keyboard_pos < len(keyboard) - 1 and symbol == keyboard[keyboard_pos + 1]:
			keyboard_pos += 1
		else:
			return False
		text_pos += 1
	global all_chars
	for char in all_chars:
		if not char in keyboard:
			keyboard += char
	return keyboard
for query in range(queries):
	text = sys.stdin.readline().strip()
	keyboard = findIdealKeyboard(text)
	if keyboard:
		print('YES')
		print(keyboard)
	else:
		print('NO')


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	s = inputstring()
	ans = collections.deque()
	alphabet = ['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']
	ans.append(s[0])
	good = True
	for i in range(1, len(s)):
		if s[i] not in ans:
			if ans[0] == s[i - 1]:
				ans.appendleft(s[i])
			elif ans[len(ans) - 1] == s[i - 1]:
				ans.append(s[i])
			else:
				good = False
				break
		else:
			ind = -1
			prevind = -1
			for j in range(len(ans)):
				if ans[j] == s[i]:
					ind = j
				if ans[j] == s[i - 1]:
					prevind = j
			if abs(ind - prevind) > 1:
				good = False
				break
	if not good:
		print('NO')
	else:
		print('YES')
		for c in ans:
			print(c, end='')
		for c in alphabet:
			if c not in ans:
				print(c, end='')
		print()


def process(s):
	g = {}
	n = len(s)
	for i in range(n - 1):
		(c1, c2) = (s[i], s[i + 1])
		if c1 not in g:
			g[c1] = set([])
		if c2 not in g:
			g[c2] = set([])
		g[c1].add(c2)
		g[c2].add(c1)
		if len(g[c1]) > 2:
			return ['NO', '']
		if len(g[c2]) > 2:
			return ['NO', '']
	words = ''
	seen = set([])
	while len(seen) < len(g):
		my_letter = None
		my_word = []
		for w in g:
			if w not in seen:
				my_letter = w
				break
		if my_letter is not None:
			my_word = my_letter
			start = my_letter
			seen.add(my_letter)
			while True:
				next_letter = None
				for w in g[start]:
					if w not in seen:
						next_letter = w
						my_word = my_word + next_letter
						seen.add(next_letter)
						break
				if next_letter is None:
					break
				else:
					start = next_letter
			start = my_letter
			while True:
				next_letter = None
				for w in g[start]:
					if w not in seen:
						next_letter = w
						my_word = next_letter + my_word
						seen.add(next_letter)
						break
				if next_letter is None:
					break
				else:
					start = next_letter
			if len(my_word) > 2:
				if len(g[my_word[0]]) == 2 or len(g[my_word[-1]]) == 2:
					return ['NO', '']
			words = words + my_word
	for i in range(26):
		c = chr(i + ord('a'))
		if c not in g:
			words += c
	return ['YES', words]
t = int(input())
for i in range(t):
	s = input()
	(a, b) = process(s)
	if a == 'NO':
		print('NO')
	else:
		print('YES')
		print(b)


a_lowercase = 'abcdefghijklmnopqrstuvwxyz'
t = int(input())
for _ in range(t):
	s = input()
	pos = 0
	keyboard = []
	can = True
	for si in s:
		if si in keyboard:
			if pos + 1 < len(keyboard) and keyboard[pos + 1] == si:
				pos += 1
			elif pos - 1 >= 0 and keyboard[pos - 1] == si:
				pos -= 1
			else:
				can = False
				break
		elif pos == len(keyboard) - 1:
			keyboard.append(si)
			pos += 1
		elif pos == 0:
			keyboard.insert(0, si)
		else:
			can = False
			break
	if can:
		for a in a_lowercase:
			if a not in keyboard:
				keyboard.append(a)
		print('YES')
		print(''.join(keyboard))
	else:
		print('NO')


t = int(input())
for _ in range(t):
	a = input()
	from collections import defaultdict
	b = defaultdict(set)
	l = len(a)
	if l == 1:
		print('YES')
		b = [i for i in range(1, 27)]
		for i in b:
			print(chr(96 + i), end='')
		print()
	else:
		w = 0
		for i in range(l - 1):
			b[a[i]].add(a[i + 1])
			b[a[i + 1]].add(a[i])
		(p, q) = (0, 0)
		for i in b:
			if len(b[i]) == 1:
				q += 1
			if len(b[i]) > 2:
				w += 1
				break
		if q == 2 and w == 0:
			print('YES')
			for i in b:
				if len(b[i]) == 1:
					p = i
					break
			s = ''
			z = set()
			l = len(b)
			q = 0
			while q != l:
				s += p
				z.add(p)
				q = q + 1
				for i in b[p]:
					if i in z:
						continue
					else:
						p = i
						continue
			for i in range(1, 27):
				if chr(96 + i) in z:
					continue
				else:
					s += chr(96 + i)
			print(s)
		else:
			print('NO')


t = int(input())
for you in range(t):
	s = input()
	lfi = [s[0]]
	poss = 1
	curr = 0
	n = len(s)
	for i in range(1, n):
		if curr == 0 and len(lfi) == 1:
			lfi.append(s[i])
			curr += 1
		elif curr == 0 and len(lfi) > 1:
			if lfi[curr + 1] == s[i]:
				curr += 1
			else:
				lfi = [s[i]] + lfi
				curr = 0
		elif curr == len(lfi) - 1:
			if lfi[curr - 1] == s[i]:
				curr -= 1
			else:
				lfi.append(s[i])
				curr += 1
		elif lfi[curr + 1] == s[i]:
			curr += 1
		elif lfi[curr - 1] == s[i]:
			curr -= 1
		else:
			poss = 0
			break
	if poss == 0:
		print('NO')
	else:
		arr = [0 for i in range(26)]
		for i in lfi:
			arr[ord(i) - 97] += 1
		for i in arr:
			if i > 1:
				poss = 0
				break
		if poss == 0:
			print('NO')
		else:
			print('YES')
			for i in lfi:
				print(i, end='')
			for i in range(26):
				if arr[i] == 0:
					print(chr(97 + i), end='')
			print()


from collections import deque
a = ord('a')

class key:
	__slots__ = ('adj', 'l', 'r', 'c', 'v', 'd')

	def __init__(self, c):
		(self.adj, self.l, self.r, self.c, self.v, self.d) = (set(), None, None, c, False, False)

	def connect(self, o) -> None:
		self.adj.add(o)
		o.adj.add(self)

def solve():
	global a
	s = input()
	lk = []
	for i in range(ord('z') - a + 1):
		lk.append(key(i))
	for i in range(1, len(s)):
		lk[ord(s[i]) - a].connect(lk[ord(s[i - 1]) - a])
	res = []
	can = any([len(k.adj) > 2 for k in lk]) == False
	if can:
		q = deque()
		for t in lk:
			if t.v == True:
				continue
			q.append(t)
			while len(q):
				k = q.pop()
				while len(k.adj) > 0:
					x = k.adj.pop()
					if x.v:
						can = False
						break
					x.v = True
					if k.l == None and x.r == None:
						k.l = x
						x.adj.remove(k)
						x.r = k
						q.append(x)
					elif k.r == None and x.l == None:
						k.r = x
						x.adj.remove(k)
						x.l = k
						q.append(x)
					else:
						can = False
						break
				if can == False:
					break
			if can == False:
				break
		if can:
			for k in lk:
				if k.d:
					continue
				x = k
				while x.l != None:
					x = x.l
				while x != None:
					x.d = True
					res.append(chr(x.c + a))
					x = x.r
	if can and len(res) == 26:
		print('YES')
		print(''.join(res))
	else:
		print('NO')
t = int(input())
while t > 0:
	t -= 1
	solve()


from string import ascii_lowercase as al
for _ in range(int(input())):
	s = input()
	if len(s) == 1:
		print('YES')
		print(al)
		continue
	adj = {x: set() for x in al}
	possible = True
	unused = set(al)
	for (i, c) in enumerate(s[:-1]):
		adj[c].add(s[i + 1])
		adj[s[i + 1]].add(c)
		if c in unused:
			unused.remove(c)
		if s[i + 1] in unused:
			unused.remove(s[i + 1])
	impossible = False
	out = []
	for c in adj:
		l = list(adj[c])
		if len(l) > 2:
			impossible = True
		elif len(l) == 1:
			out.append(c)
	if len(out) != 2:
		impossible = True
	if not impossible:
		print('YES')
		end = out.pop()
		used = set(al) - unused
		used.remove(out[0])
		while used:
			n = adj[out[-1]].pop()
			if n in out:
				continue
			out.append(n)
			if n in used:
				used.remove(n)
		out = ''.join(out) + ''.join(unused)
		print(out)
	else:
		print('NO')


t = int(input())
d = ['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']
for _ in range(t):
	a = list(input())
	n = len(a)
	s = [a[0]]
	siz = 1
	j = 0
	flag = 1
	for i in range(1, n):
		if siz == 1:
			s.append(a[i])
			siz += 1
			j += 1
		elif j < siz and j + 1 < siz and (a[i] == s[j + 1]):
			j += 1
		elif j > 0 and j - 1 >= 0 and (a[i] == s[j - 1]):
			j -= 1
		elif j == 0 and j + 1 < siz and (a[i] != s[j + 1]) and (a[i] not in s):
			s = [a[i]] + s
			siz += 1
		elif j == siz - 1 and j - 1 >= 0 and (a[i] != s[j - 1]) and (a[i] not in s):
			s = s + [a[i]]
			siz += 1
			j += 1
		else:
			flag = 0
			break
	if flag == 1:
		print('YES')
		temp = ''
		for i in d:
			if i not in s:
				temp = temp + i
		print(''.join(s) + temp)
	else:
		print('NO')


from collections import defaultdict
from string import ascii_lowercase

def main():
	t = int(input().strip())
	for _ in range(t):
		s = input().strip()
		adj = defaultdict(set)
		for (a, b) in zip(s, s[1:]):
			adj[a].add(b)
			adj[b].add(a)
		if any((len(vs) > 2 for vs in adj.values())):
			print('NO')
			continue
		result = []
		seen = set()
		fail = False
		for c in ascii_lowercase:
			if c in seen:
				continue
			if not adj[c]:
				result.append(c)
				seen.add(c)
				continue
			parent = None
			u = c
			while len(adj[u]) > 1:
				if len(adj[u]) > 2:
					fail = True
					break
				(u, parent) = (min(adj[u] - {parent}), u)
				if u == c:
					fail = True
					break
			if fail:
				break
			result.append(u)
			seen.add(u)
			parent = u
			u = min(adj[u])
			while True:
				result.append(u)
				seen.add(u)
				if len(adj[u]) == 1:
					break
				(u, parent) = (min(adj[u] - {parent}), u)
		if fail:
			print('NO')
		else:
			print('YES')
			print(''.join(result))
main()


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	prev = s[0]
	d = {s[0]: 200}
	slots = [None] * 500
	slots[200] = s[0]
	for i in range(1, n):
		c = s[i]
		if c in d:
			if abs(d[c] - d[prev]) != 1:
				print('NO')
				break
		elif slots[d[prev] - 1] is None:
			slots[d[prev] - 1] = c
			d[c] = d[prev] - 1
		elif slots[d[prev] + 1] is None:
			slots[d[prev] + 1] = c
			d[c] = d[prev] + 1
		else:
			print('NO')
			break
		prev = c
	else:
		print('YES')
		ans = []
		i = 0
		while slots[i] is None:
			i += 1
		while slots[i] is not None:
			ans.append(slots[i])
			i += 1
		for i in range(97, 97 + 26):
			c = chr(i)
			if c not in d:
				ans.append(c)
		print(''.join(ans))


for _ in range(int(input())):
	s = input()
	n = len(s)
	ans = s[0]
	f = 0
	for i in range(1, n):
		if s[i] not in ans:
			if s[i - 1] == ans[0]:
				ans = s[i] + ans
			elif s[i - 1] == ans[-1]:
				ans = ans + s[i]
			else:
				f = 1
				break
		elif s[i - 1] + s[i] in ans or s[i] + s[i - 1] in ans:
			continue
		else:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		print('YES')
		r = ''
		for i in range(26):
			if chr(ord('a') + i) not in ans:
				r = r + chr(ord('a') + i)
		print(ans + r)


t = int(input())
a = set((chr(x) for x in range(97, 123)))
for _ in range(t):
	s = input()
	adj = dict()
	aa = set(s)
	for c in aa:
		adj[c] = set()
	for i in range(len(s) - 1):
		adj[s[i]].add(s[i + 1])
		adj[s[i + 1]].add(s[i])
	ans = []
	flag = True
	visited = set()
	for (k, v) in adj.items():
		if k in visited:
			continue
		if len(v) > 2:
			flag = False
			break
		elif len(v) == 1:
			c = k
			while True:
				ans.append(c)
				visited.add(c)
				if len(adj[c]) > 1:
					flag = False
					break
				if not adj[c]:
					break
				c = adj[c].pop()
				adj[c].remove(ans[-1])
		elif len(v) == 0:
			visited.add(c)
			ans.append(c)
	if not flag or aa != visited:
		print('NO')
	else:
		print('YES')
		print(*ans + list(a - aa), sep='')


import collections as col

def solve():
	S = input()
	if len(S) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		return
	graph = col.defaultdict(set)
	for i in range(len(S) - 1):
		graph[S[i]].add(S[i + 1])
		graph[S[i + 1]].add(S[i])
	ones = []
	for key in graph:
		if len(graph[key]) > 2:
			print('NO')
			return
		if len(graph[key]) == 1:
			ones.append(key)
	nodes = set()
	for j in range(26):
		nodes.add(chr(ord('a') + j))

	def bfs(graph, visited, node, queue, nodes):
		visited.append(node)
		visited_dict = {node: node}
		nodes.remove(node)
		queue.append((node, None))
		queue = col.deque(queue)
		cycle = False
		while queue:
			(s, parent) = queue.popleft()
			for neighbour in graph[s]:
				if neighbour in visited_dict and neighbour != parent:
					cycle = True
				elif neighbour not in visited_dict:
					visited.append(neighbour)
					visited_dict[neighbour] = neighbour
					nodes.remove(neighbour)
					queue.append((neighbour, s))
		return (cycle, nodes, visited)
	connected_components = []
	if not ones:
		print('NO')
		return
	while nodes and ones:
		node = ones.pop()
		if node not in nodes:
			continue
		(ans, nodes, visited) = bfs(graph, [], node, [], nodes)
		if ans:
			print('NO')
			return
		connected_components.append(visited)
	ans = ''
	for c in connected_components:
		ans += ''.join(visited)
	for x in nodes:
		ans += x
	print('YES')
	print(ans)
	return
for _ in range(int(input())):
	solve()


import sys
input = sys.stdin.readline
for _ in range(int(input().strip())):
	inp = list(input().strip())
	if len(inp) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
	else:
		dic = {}
		for i in range(26):
			dic[chr(i + ord('a'))] = [-1, -1]
		val = True
		for i in range(len(inp) - 1):
			cur = inp[i]
			nex = inp[i + 1]
			if dic[cur][0] == nex or dic[cur][1] == nex or dic[nex][0] == cur or (dic[nex][1] == cur):
				pass
			elif dic[cur][0] == -1 and dic[nex][0] == -1:
				dic[cur][0] = nex
				dic[nex][0] = cur
			elif dic[cur][0] == -1 and dic[nex][1] == -1:
				dic[cur][0] = nex
				dic[nex][1] = cur
			elif dic[cur][1] == -1 and dic[nex][0] == -1:
				dic[cur][1] = nex
				dic[nex][0] = cur
			elif dic[cur][1] == -1 and dic[nex][1] == -1:
				dic[cur][1] = nex
				dic[nex][1] = cur
			else:
				val = False
				break
		if not val:
			print('NO')
		else:
			done = set()
			st = None
			for x in dic:
				if (dic[x][0] == -1 or dic[x][1] == -1) and (not (dic[x][0] == -1 and dic[x][1] == -1)):
					st = x
					break
			if st is None:
				print('NO')
			else:
				print('YES')
				ans = []
				while st not in done and st != -1:
					ans.append(st)
					done.add(st)
					nex = dic[st]
					if nex[0] in done:
						st = nex[1]
					else:
						st = nex[0]
				for x in 'abcdefghijklmnopqrstuvwxyz':
					if x not in done:
						ans.append(x)
				print(''.join(ans))


import sys
from collections import deque
from string import ascii_lowercase

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
for _ in range(INT()):
	pwd = input()
	que = deque([pwd[0]])
	S = set(pwd[0])
	cur = 0
	for s in pwd[1:]:
		ln = len(que)
		if s not in S:
			if cur == ln - 1:
				que.append(s)
				S.add(s)
				cur += 1
			elif cur == 0:
				que.appendleft(s)
				S.add(s)
			else:
				NO()
				break
		elif cur == ln - 1:
			if que[cur - 1] == s:
				cur -= 1
			else:
				NO()
				break
		elif cur == 0:
			if que[cur + 1] == s:
				cur += 1
			else:
				NO()
				break
		elif que[cur - 1] == s:
			cur -= 1
		elif que[cur + 1] == s:
			cur += 1
		else:
			NO()
			break
	else:
		for a in ascii_lowercase:
			if a not in S:
				que.append(a)
		YES()
		print(''.join(que))


def dfs(v, prev):
	global used, res, ans
	used[v] = True
	myans = ''
	for u in graph[v]:
		if u == prev:
			continue
		if used[u]:
			res = False
			return
		dfs(u, v)
for _ in range(int(input())):
	s = input()
	n = len(s)
	if n == 1:
		print('YES')
		print(*[chr(i + 97) for i in range(26)], sep='')
		continue
	graph = [set() for _ in range(26)]
	for i in range(n):
		char = s[i]
		code = ord(char) - 97
		if i != n - 1:
			graph[code].add(ord(s[i + 1]) - 97)
			graph[ord(s[i + 1]) - 97].add(code)
		if i != 0:
			graph[code].add(ord(s[i - 1]) - 97)
			graph[ord(s[i - 1]) - 97].add(code)
	graph = [list(i) for i in graph]
	cnt = 0
	ones = []
	twos = []
	for i in graph:
		cnt += len(i)
		if len(i) == 1:
			ones.append(i)
		elif len(i) == 2:
			twos.append(i)
		elif len(i) != 0:
			cnt += 1000000000.0
			break
	if len(ones) != 2 or cnt / 2 != len({i for i in s}) - 1:
		print('NO')
		continue
	start = 0
	for (num, i) in enumerate(graph):
		if i in ones:
			start = num
			break
	started = True
	err = False
	ans = chr(start + 97)
	while (len(graph[start]) != 1 or started) and (not err):
		started = False
		if chr(graph[start][0] + 97) not in ans:
			ans += chr(graph[start][0] + 97)
			start = graph[start][0]
		elif ans[-2] != chr(graph[start][0] + 97):
			err = True
			break
		else:
			ans += chr(graph[start][1] + 97)
			start = graph[start][1]
	if err:
		print('NO')
		continue
	for i in range(26):
		if chr(i + 97) not in ans:
			ans += chr(i + 97)
	print('YES')
	print(ans)


test = 'qwertyuiopasdfghjklzxcvbnm'
for i in range(int(input())):
	s = input()
	ans = s[0]
	a = [False] * 26
	b = [False] * 26
	c = [False] * 26
	check = False
	c[ord(s[0]) - 97] = True
	for i in range(1, len(s)):
		if not c[ord(s[i]) - 97]:
			c[ord(s[i]) - 97] = True
			if not a[ord(s[i - 1]) - 97]:
				ans += s[i]
				a[ord(s[i - 1]) - 97] = True
				b[ord(s[i]) - 97] = True
			elif not b[ord(s[i - 1]) - 97]:
				ans = s[i] + ans
				b[ord(s[i - 1]) - 97] = True
				a[ord(s[i]) - 97] = True
			else:
				check = True
				break
		else:
			ind = ans.index(s[i])
			if not b[ord(s[i]) - 97] and a[ord(s[i]) - 97]:
				if ans[ind + 1] != s[i - 1]:
					check = True
					break
			elif b[ord(s[i]) - 97] and a[ord(s[i]) - 97]:
				if ans[ind + 1] != s[i - 1] and ans[ind - 1] != s[i - 1]:
					check = True
					break
			elif ans[ind - 1] != s[i - 1]:
				check = True
				break
	if check:
		print('NO')
	else:
		for i in test:
			if i not in ans:
				ans += i
		print('YES')
		print(ans)


from collections import defaultdict
l = []
for i in range(26):
	l.append(chr(97 + i))

def dfs(node, d, ans, v):
	no = ord(node) - ord('a')
	if not v[no]:
		ans.append(node)
		v[no] = 1
		for ni in d[node]:
			(ans, v) = dfs(ni, d, ans, v)
	return (ans, v)
for ti in range(int(input())):
	p = input()
	d = defaultdict(list)
	v = [0] * 26
	for i in range(1, len(p)):
		if p[i - 1] not in d[p[i]]:
			d[p[i]].append(p[i - 1])
		if p[i] not in d[p[i - 1]]:
			d[p[i - 1]].append(p[i])
	op = 0
	mp = 0
	for di in d:
		if len(d[di]) == 1:
			op = di
		elif len(d[di]) > 2:
			mp = 1
	if len(p) > 1:
		if not op or mp:
			print('NO')
			continue
	else:
		op = p[0]
	ans = []
	(ans, v) = dfs(op, d, ans, v)
	for li in l:
		dfs(li, d, ans, v)
	print('YES')
	print(''.join(ans))


import sys
import bisect
from collections import deque

def no():
	print('NO')

def dist(z, c):
	return (z[0] - c[0]) * (z[0] - c[0]) + (z[1] - c[1]) * (z[1] - c[1])

def vec(z, c):
	return z[0] * c[1] - z[1] * c[0]

def pro(z, c):
	return [z[0] - c[0], z[1] - c[1]]

def main():
	s = list(sys.stdin.readline())[:-1]
	cl = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
	cl1 = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j', 10: 'k', 11: 'l', 12: 'm', 13: 'n', 14: 'o', 15: 'p', 16: 'q', 17: 'r', 18: 's', 19: 't', 20: 'u', 21: 'v', 22: 'w', 23: 'x', 24: 'y', 25: 'z'}
	n = len(s)
	w = [set() for i in range(26)]
	for i in range(n - 1):
		(x, y) = (cl[s[i]], cl[s[i + 1]])
		w[x].add(y)
		w[y].add(x)
	res = []
	e = []
	for i in range(26):
		if len(w[i]) > 2:
			print('NO')
			return 0
		elif len(w[i]) == 1:
			e.append(i)
		elif len(w[i]) == 0:
			res.append(i)
	used = [0 for i in range(26)]
	for i in e:
		if used[i]:
			continue
		q = deque()
		q.append(i)
		while len(q):
			v = q.pop()
			used[v] = 1
			res.append(v)
			for u in w[v]:
				if not used[u]:
					q.append(u)
	if len(res) != 26:
		print('NO')
		return 0
	print('YES')
	for i in res:
		print(cl1[i], end='')
	print()
for i in range(int(sys.stdin.readline())):
	main()


def dfs(u, v):
	ans.append(chr(v + ord('a')))
	used[v] = 1
	if len(a[v]) > 2:
		return False
	for i in a[v]:
		if i != u:
			if used[i] == 1:
				return False
			else:
				return dfs(v, i)
	return True
t = int(input())
for i in range(t):
	s = input()
	a = [set() for j in range(26)]
	for j in range(len(s) - 1):
		a[ord(s[j]) - ord('a')].add(ord(s[j + 1]) - ord('a'))
		a[ord(s[j + 1]) - ord('a')].add(ord(s[j]) - ord('a'))
	used = [0] * 26
	ans = []
	flag = False
	for j in range(26):
		if len(a[j]) == 1 and used[j] == 0:
			if not dfs(-1, j):
				print('NO')
				flag = True
				break
	if flag:
		continue
	for j in range(26):
		if len(a[j]) > 0 and used[j] == 0:
			print('NO')
			flag = True
			break
		elif len(a[j]) == 0:
			ans.append(chr(j + ord('a')))
	if flag:
		continue
	print('YES')
	for j in ans:
		print(j, end='')
	print()


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

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

def si():
	return input()

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

def msi():
	return map(str, input().strip().split(' '))

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

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
from collections import deque, Counter, OrderedDict, defaultdict
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

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

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

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 read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		s = si()
		n = len(s)
		l = defaultdict(list)
		f = [0] * 30
		if n == 1:
			print('YES')
			print(abc)
			continue
		for i in range(n):
			if i == 0:
				l[abd[s[i]]].append(abd[s[i + 1]])
				f[abd[s[i]]] = 1
			elif i == n - 1:
				l[abd[s[i]]].append(abd[s[i - 1]])
				f[abd[s[i]]] = 1
			else:
				l[abd[s[i]]].append(abd[s[i + 1]])
				f[abd[s[i]]] = 1
				l[abd[s[i]]].append(abd[s[i - 1]])
		for i in range(26):
			l[i] = list(set(l[i]))
		ans = ''
		f = [0] * 30
		pos = -1
		for i in range(26):
			if len(l[i]) == 1:
				pos = i
			if len(l[i]) > 2:
				pos = -1
				break
		if pos == -1:
			print('NO')
			continue
		ans += abc[pos]
		f[pos] = 1
		ll = len(list(set(s)))
		qq = 0
		while len(ans) != ll:
			pos = abd[ans[len(ans) - 1]]
			for j in range(len(l[pos])):
				x = l[pos][j]
				if f[x]:
					continue
				f[x] = 1
				ans += abc[l[pos][j]]
				break
		f = [0] * 30
		for i in range(n):
			f[abd[s[i]]] = 1
		for i in range(26):
			if f[i] == 0:
				ans += abc[i]
		print('YES')
		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')

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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import string

def solve():

	def dfs(v):
		if visited[v]:
			return
		dfsOrder.append(v)
		visited[v] = True
		for u in graph[v]:
			dfs(u)
		return
	s = input()
	graph = {}
	for c in string.ascii_lowercase:
		graph[c] = set()
	oldChar = s[0]
	for c in s[1:]:
		graph[oldChar].add(c)
		graph[c].add(oldChar)
		oldChar = c
	degree = {}
	for v in graph:
		degree[v] = len(graph[v])
		if degree[v] > 2:
			print('NO')
			return
	visited = {}
	dfsOrder = []
	for v in graph:
		visited[v] = False
	for v in graph:
		if degree[v] < 2:
			dfs(v)
	for v in graph:
		if not visited[v]:
			print('NO')
			return
	print('YES')
	print(''.join(dfsOrder))
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	q = input()
	ans = q[0]
	test = [0] * 26
	j = 0
	c = 1
	for i in q[1:]:
		if j > 0 and ans[j - 1] == i:
			j -= 1
			continue
		if j < len(ans) - 1 and ans[j + 1] == i:
			j += 1
			continue
		if j == 0:
			ans = i + ans
			continue
		if j == len(ans) - 1:
			ans += i
			j += 1
			continue
		c = 0
	for i in ans:
		test[ord(i) - 97] += 1
	for i in range(26):
		if test[i] > 1:
			c = 0
		if test[i] == 0:
			ans += chr(i + 97)
	if c:
		print('YES')
		print(ans)
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	layout = []
	used_characters = set()
	ind = 0
	flag = 1
	for char in s:
		if not layout:
			used_characters.add(char)
			layout.append(char)
		elif char in used_characters:
			if 0 < ind and layout[ind - 1] == char:
				ind -= 1
			elif ind < len(layout) - 1 and layout[ind + 1] == char:
				ind += 1
			else:
				flag = 0
				break
		elif ind == 0:
			used_characters.add(char)
			layout.insert(0, char)
		elif ind == len(layout) - 1:
			used_characters.add(char)
			layout.append(char)
			ind += 1
		else:
			flag = 0
			break
	if flag:
		print('YES')
		for unicode_code_point in range(97, 123):
			if chr(unicode_code_point) not in used_characters:
				layout.append(chr(unicode_code_point))
		print(''.join(layout))
	else:
		print('NO')


import os
from io import BytesIO, IOBase
import sys
from math import ceil
from collections import Counter

def main():
	for t in range(int(input())):
		s = input().rstrip()
		n = len(s)
		a = [s[0]]
		c = set()
		c.add(s[0])
		ans = 'YES'
		for i in range(1, n):
			if s[i] not in c:
				y = a.index(s[i - 1])
				c.add(s[i])
				if y == 0 or y == len(a) - 1:
					if y == 0:
						a.insert(0, s[i])
					else:
						a.append(s[i])
				else:
					ans = 'NO'
					break
			else:
				y = a.index(s[i])
				z = a.index(s[i - 1])
				if abs(y - z) != 1:
					ans = 'NO'
					break
		print(ans)
		if ans == 'YES':
			for i in range(97, 97 + 26):
				i = chr(i)
				if i not in c:
					a.append(i)
			print(''.join(a))
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()


import collections as cc

def dfs(i):
	ans.append(i)
	for j in f[i]:
		if j not in ans:
			dfs(j)
for tc in range(int(input())):
	s = input()
	if len(s) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	ans = []
	g = s[0]
	f = cc.defaultdict(set)
	for i in range(1, len(s)):
		f[s[i]].add(s[i - 1])
		f[s[i - 1]].add(s[i])
	ff = 1
	s = -1
	for i in f:
		if len(f[i]) > 2:
			ff = 0
			break
		if len(f[i]) == 1:
			s = i
	if ff and s != -1:
		dfs(i)
		an = ''.join(ans)
		for i in 'abcdefghijklmnopqrstuvwxyz':
			if i not in an:
				an += i
		print('YES')
		print(an)
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	s1 = s[0]
	ans = 'YES'
	for i in range(len(s) - 1):
		if s[i + 1] not in s1:
			x = s1.find(s[i])
			if x == len(s1) - 1:
				s1 += s[i + 1]
			elif x == 0:
				s1 = s[i + 1] + s1
			else:
				ans = 'NO'
				break
		else:
			x1 = s1.find(s[i + 1])
			x2 = s1.find(s[i])
			if abs(x2 - x1) > 1:
				ans = 'NO'
				break
	print(ans)
	if ans == 'YES':
		for i in range(26):
			if chr(ord('a') + i) not in s1:
				s1 += chr(ord('a') + i)
		print(s1)


from collections import defaultdict as d
t = int(input())
for _ in range(t):
	s = input()
	a = d(set)
	for i in range(len(s) - 1):
		a[s[i]].add(s[i + 1])
		a[s[i + 1]].add(s[i])
	one = 0
	tab = []
	perfect = True
	for (key, values) in a.items():
		if len(values) == 1:
			one += 1
			tab.append(key)
		elif len(values) > 2:
			perfect = False
	if not perfect:
		print('NO')
	elif len(set(s)) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
	elif one == 2:
		print('YES')
		r = tab[0]
		curr = r
		while len(r) < len(set(s)):
			v = list(a[curr])
			if v[0] not in r:
				r += v[0]
				curr = v[0]
			elif len(v) == 2:
				if v[1] not in r:
					r += v[1]
					curr = v[1]
		for c in 'abcdefghijklmnopqrstuvwxyz':
			if c not in r:
				r += c
		print(r)
	else:
		print('NO')


n = int(input())
k = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
	s = list(input())
	key = []
	key.append(s[0])
	c = 0
	for i in range(1, len(s)):
		if s[i] not in key:
			if key[0] == s[i - 1]:
				key.insert(0, s[i])
			elif key[-1] == s[i - 1]:
				key.append(s[i])
			else:
				c = 1
				break
		elif s[i] in key:
			check = 0
			ind = key.index(s[i])
			for j in range(max(0, ind - 1), min(len(key), ind + 2), 1):
				if key[j] == s[i - 1]:
					check = 1
			if check == 0:
				c = 1
				break
	if c == 0:
		for i in range(26):
			if k[i] not in key:
				key.append(k[i])
		print('YES')
		print(*key, sep='')
	else:
		print('NO')


from math import ceil, sqrt, gcd

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

def si():
	return input()

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

def li():
	return list(mi())
t = ii()
while t:
	t -= 1
	m = {}
	for i in range(26):
		m[i] = []
	s = si()
	n = len(s)
	f = 0
	if n == 1:
		print('YES')
		for i in range(26):
			print(chr(i + 97), end='')
		print()
	else:
		m[ord(s[0]) - ord('a')].append(ord(s[1]) - ord('a'))
		for i in range(1, n - 1):
			x = ord(s[i + 1]) - ord('a')
			y = ord(s[i - 1]) - ord('a')
			z = ord(s[i]) - ord('a')
			if x not in m[z]:
				m[z].append(x)
			if y not in m[z]:
				m[z].append(y)
		y = ord(s[n - 2]) - ord('a')
		z = ord(s[n - 1]) - ord('a')
		if y not in m[z]:
			m[z].append(y)
		f = -1
		for i in m.keys():
			if len(m[i]) == 1:
				f = i
				break
		if f == -1:
			print('NO')
		else:
			s1 = chr(f + 97)
			s1 += chr(m[f][0] + 97)
			ch = m[f][0]
			par = f
			n -= 2
			f = 0
			while 1:
				if n == 0:
					break
				if len(m[ch]) == 2:
					if par != m[ch][0]:
						s1 += chr(m[ch][0] + 97)
						par = ch
						ch = m[ch][0]
					else:
						s1 += chr(m[ch][1] + 97)
						par = ch
						ch = m[ch][1]
				elif len(m[ch]) == 1:
					break
				else:
					f = 1
					break
				n -= 1
			if f == 1:
				print('NO')
			else:
				print('YES')
				print(s1, end='')
				s1 = list(s1)
				for i in range(26):
					if chr(i + 97) not in s1:
						print(chr(i + 97), end='')
				print()


from math import factorial
from collections import Counter
from heapq import heapify, heappop, heappush
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 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)
mod = 1000000007
inputI = int(input())
INF = float('inf')
ad = ord('a')

def main():
	N = inputI
	for _ in range(N):
		s = input()
		res = [s[0]]
		tag = 0
		if len(s) > 1:
			res.append(s[1])
			tag += 1
		rec = set(res)
		for i in s[2:]:
			if tag == 0:
				if res[tag + 1] == i:
					tag += 1
				elif i not in rec:
					res.insert(0, i)
				else:
					print('NO')
					break
			elif tag == len(res) - 1:
				if res[tag - 1] == i:
					tag -= 1
				elif i not in rec:
					res.append(i)
					tag += 1
				else:
					print('NO')
					break
			elif i == res[tag + 1]:
				tag += 1
			elif i == res[tag - 1]:
				tag -= 1
			else:
				print('NO')
				break
			rec.add(i)
		else:
			print('YES')
			for i in range(26):
				c = chr(ad + i)
				if c not in rec:
					res.append(c)
			print(''.join(res))
main()


import math
t = int(input())
for _ in range(t):
	s = input()
	s = list(s)
	alpha = list('abcdefghijklmnopqrstuvwxyz')
	flag = 0
	visited = {s[0]: 26}
	alpha.remove(s[0])
	pos = 26
	for i in range(1, len(s)):
		if s[i] not in list(visited.keys()):
			if pos + 1 in list(visited.values()) and pos - 1 in list(visited.values()):
				print('NO')
				flag = 1
				break
			else:
				if pos + 1 not in list(visited.values()):
					visited[s[i]] = pos + 1
					pos = pos + 1
				else:
					visited[s[i]] = pos - 1
					pos = pos - 1
				alpha.remove(s[i])
		elif abs(pos - visited[s[i]]) > 1:
			print('NO')
			flag = 1
			break
		else:
			pos = visited[s[i]]
	if flag == 0:
		print('YES')
		visited = list(visited.items())
		visited = sorted(visited, key=lambda visited: visited[1])
		res = []
		for item in visited:
			res.append(item[0])
		res = res + alpha
		print(''.join(res))


from sys import stdin
input = stdin.readline
for xoxo in range(1):
	for _ in range(int(input())):
		s = input()
		l = []
		alp = []
		a = []
		an = []
		g = []
		ans = 0
		for i in range(26):
			alp.append(chr(i + 97))
			g.append([])
		for i in range(len(s) - 1):
			l.append(ord(s[i]) - 97)
		if len(l) == 1 or len(l) == 2:
			print('YES')
			vis = [0] * 26
			for j in range(len(l)):
				vis[l[j]] = 1
			for i in range(26):
				if vis[i] == 1:
					print(alp[i], end='')
			for i in range(26):
				if vis[i] == 0:
					print(alp[i], end='')
			print()
			continue
		for i in range(len(l) - 1):
			if l[i + 1] in g[l[i]]:
				continue
			g[l[i]].append(l[i + 1])
			g[l[i + 1]].append(l[i])
			if len(g[l[i]]) > 2 or len(g[l[i + 1]]) > 2:
				ans = -1
				break
		for i in range(26):
			if len(g[i]) > 2:
				ans = -1
				break
			if len(g[i]) == 1:
				a.append(i)
		if len(a) != 2 or ans == -1:
			print('NO')
			continue
		else:
			vis = [0] * 26
			an.append(a[0])
			vis[a[0]] = 1
			k = a[0]
			while k != a[1]:
				for j in range(len(g[k])):
					if vis[g[k][j]] == 0:
						vis[g[k][j]] = 1
						an.append(g[k][j])
						k = g[k][j]
						break
			vis[a[1]] = 1
			print('YES')
			for i in an:
				print(alp[i], end='')
			for i in range(26):
				if vis[i] == 0:
					print(alp[i], end='')
			print()


import string
t = int(input())
for _ in range(t):
	mp = [[0] * 26 for _ in range(26)]
	s = input()
	for i in range(len(s) - 1):
		mp[ord(s[i]) - ord('a')][ord(s[i + 1]) - ord('a')] = 1
		mp[ord(s[i + 1]) - ord('a')][ord(s[i]) - ord('a')] = 1
	flag = True
	end = list()
	ans = ''
	for i in range(26):
		cnt = 0
		for j in range(26):
			if mp[i][j]:
				cnt += 1
		if cnt > 2:
			flag = False
		elif cnt == 1:
			if len(end) < 2:
				end.append(i)
			else:
				flag = False
		elif cnt == 0:
			ans += chr(i + ord('a'))
	if flag and len(end) == 2:
		ans += chr(end[0] + ord('a'))
		ad = end[0]
		bf = -1
		while ad != end[1]:
			for i in range(26):
				if mp[ad][i] and i != bf:
					bf = ad
					ad = i
					ans += chr(ad + ord('a'))
					break
		print('YES')
		print(ans)
	elif len(s) == 1:
		print('YES')
		print(string.ascii_lowercase)
	else:
		print('NO')


from sys import *
from math import *
t = int(input())
for _ in range(t):
	s = input()
	ans = []
	f1 = 0
	j = 0
	for i in range(len(s)):
		if s[i] not in ans:
			if j != 0 and j != len(ans) - 1:
				f1 = 1
				break
			elif j == len(ans) - 1 and j != 0:
				j += 1
				ans.insert(j, s[i])
			else:
				ans.insert(0, s[i])
		else:
			f = 0
			for j in range(len(ans)):
				if ans[j] == s[i]:
					break
			if j > 0:
				if ans[j - 1] == s[i - 1]:
					f = 1
			if j < len(ans) - 1 and f == 0:
				if ans[j + 1] == s[i - 1]:
					f = 1
			if f == 0:
				f1 = 1
				break
	if f1 == 1:
		print('NO')
	else:
		print('YES')
		for i in range(97, 123):
			if chr(i) not in ans:
				ans.append(chr(i))
		print(*ans, sep='')


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 ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

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 fsep():
	return map(float, inp().split())

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

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

def pow(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
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

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

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

def solve():
	s = inp()
	l = len(s)
	d = defaultdict(set)
	ans = ''
	if l == 1:
		print('YES')
		for i in range(ord('a'), ord('z') + 1):
			ans += chr(i)
		print(ans)
		return
	for i in range(1, l - 1):
		d[s[i]].add(s[i + 1])
		d[s[i]].add(s[i - 1])
	d[s[0]].add(s[1])
	d[s[l - 1]].add(s[l - 2])
	temp = []
	for i in d.keys():
		if len(d[i]) > 2:
			print('NO')
			return
		temp.append(len(d[i]))
	if temp.count(2) > 24 or temp.count(1) < 1:
		print('NO')
		return
	for i in d.keys():
		if len(d[i]) == 1:
			st = i
			break
	used = set()
	ans = ''
	q = deque([st])
	while q:
		v = q.popleft()
		ans += v
		used.add(v)
		for i in d[v]:
			if i not in used:
				q.append(i)
	for i in range(ord('a'), ord('z') + 1):
		c = chr(i)
		if c not in ans:
			ans += c
	print('YES')
	print(ans)
testcase(int(inp()))


import math
t = int(input())
for _ in range(t):
	s = input()
	temp = s[0]
	i = 1
	j = 0
	slen = len(s)
	tlen = len(temp)
	fl = 0
	seen = set()
	seen.add(s[0])
	while i < slen:
		if s[i] == temp[j]:
			i += 1
		elif j > 0 and temp[j - 1] == s[i]:
			j -= 1
			i += 1
		elif j < tlen - 1 and temp[j + 1] == s[i]:
			j += 1
			i += 1
		elif j == 0 and s[i] not in seen:
			temp = s[i] + temp
			tlen += 1
			seen.add(s[i])
			i += 1
		elif j == tlen - 1 and s[i] not in seen:
			temp += s[i]
			tlen += 1
			j += 1
			seen.add(s[i])
			i += 1
		else:
			fl = 1
			break
	if fl == 1:
		print('NO')
		continue
	print('YES')
	farr = [chr(i) for i in range(97, 97 + 26)]
	for x in temp:
		farr.remove(x)
	print(temp + ''.join(farr))


from collections import defaultdict
for _ in range(int(input())):
	s = input()
	neigh = defaultdict(set)
	leftest = s[0]
	ans = 'YES'
	for i in range(1, len(s)):
		if s[i] != s[i - 1]:
			neigh[s[i]].add(s[i - 1])
			neigh[s[i - 1]].add(s[i])
			if len(neigh[s[i]]) > 2 or len(neigh[s[i - 1]]) > 2:
				ans = 'NO'
				break
	klav = ''
	first = None
	ends = 0
	for [lett, nei] in neigh.items():
		if len(nei) == 1:
			ends += 1
			first = lett
	if ends > 2 or ans == 'NO':
		print('NO')
		continue
	if len(neigh) and ends != 2:
		print('NO')
		continue
	if first is not None:
		klav += first
		used = [False] * 26
		used[ord(first) - ord('a')] = True
		nei = list(neigh[first])
		cur = nei[0]
		while len(neigh[cur]) != 1:
			used[ord(cur) - ord('a')] = True
			klav += cur
			nei = list(neigh[cur])
			if used[ord(nei[0]) - ord('a')]:
				cur = nei[1]
			else:
				cur = nei[0]
		klav += cur
	print(ans)
	if ans == 'YES':
		for c in 'abcdefghijklmnopqrstuvwxyz':
			if c not in neigh:
				klav += c
		print(klav)


def findAnswer(string):
	(prevId, myList, visited) = (0, [], {})
	myList.append(string[0])
	visited[string[0]] = True
	for curr in range(1, len(string)):
		prevId = getIndex(string[curr], prevId, myList, visited)
		if prevId == -1:
			return 'NO'
	return getfinalAns(''.join(myList), visited)

def getIndex(currChar, prevId, myList: list, visited: dict):
	if prevId == 0:
		if len(myList) > 1 and myList[1] == currChar:
			return 1
		elif visited.get(currChar, False):
			return -1
		else:
			visited[currChar] = True
			myList.insert(0, currChar)
			return 0
	elif prevId == len(myList) - 1:
		if myList[len(myList) - 2] == currChar:
			return len(myList) - 2
		elif visited.get(currChar, False):
			return -1
		else:
			visited[currChar] = True
			myList.append(currChar)
			return len(myList) - 1
	elif myList[prevId + 1] == currChar:
		return prevId + 1
	elif myList[prevId - 1] == currChar:
		return prevId - 1
	else:
		return -1

def getfinalAns(string, visited: dict):
	myList = []
	for i in range(ord('a'), ord('z') + 1):
		if not visited.get(chr(i), False):
			myList.append(chr(i))
	return string + ''.join(myList)
t = int(input())
while t > 0:
	string = input()
	ans = findAnswer(string)
	if ans == 'NO':
		print('NO')
	else:
		print('YES')
		print(ans)
	t -= 1


t = int(input())

def kc(c):
	return ord(c) - 97

def isful(s):
	for i in s:
		if any(i):
			pass
		else:
			return False
	return True
for ti in range(t):
	s = input()
	fst = 'N'
	c1 = set()
	ma = [set() for i in range(26)]
	l = len(s)
	if l == 1:
		print('YES')
		print('qwertyuiopasdfghjklzxcvbnm')
		continue
	for (idx, i) in enumerate(s):
		if idx + 1 == l:
			ma[kc(i)].add(kc(s[idx - 1]))
		elif idx == 0:
			ma[kc(i)].add(kc(s[idx + 1]))
		else:
			ma[kc(i)].add(kc(s[idx - 1]))
			ma[kc(i)].add(kc(s[idx + 1]))
		if len(ma[kc(i)]) == 1:
			c1.add(kc(i))
		elif len(ma[kc(i)]) == 2:
			c1.discard(kc(i))
		elif len(ma[kc(i)]) > 2:
			fst = 'X'
			break
	if fst == 'X':
		print('NO')
	elif len(c1) >= 2:
		cur = c1.pop()
		kk = [cur]
		while len(ma[cur]):
			if cur in ma[cur]:
				ma[cur].discard(cur)
			if len(ma[cur]):
				one = ma[cur].pop()
				if one in kk:
					continue
				else:
					kk.append(one)
					cur = one
		for i in range(26):
			if i not in kk:
				kk.append(i)
		print('YES')
		for i in kk:
			print(chr(i + 97), end='')
		print()
	else:
		print('NO')


import math
T = int(input())
for t in range(T):
	S = input()
	fl = 0
	out = S[0]
	alph = set()
	alph.add(S[0])
	if len(S) > 1:
		out += S[1]
		alph.add(S[1])
		c = 1
		for s in range(2, len(S)):
			if c > 0 and S[s] == out[c - 1]:
				c -= 1
			elif c + 1 < len(out) and S[s] == out[c + 1]:
				c += 1
			elif S[s] not in alph:
				if c == 0:
					out = S[s] + out
					alph.add(S[s])
				elif c == len(out) - 1:
					c += 1
					out += S[s]
					alph.add(S[s])
				else:
					fl = 1
					break
			else:
				fl = 1
				break
	if fl == 1:
		print('NO')
	else:
		left = ''
		for i in range(26):
			if chr(i + 97) not in alph:
				left += chr(i + 97)
		print('YES')
		print(left + out)


from collections import defaultdict
for _ in range(int(input())):
	s = input()
	a = ''
	n = len(s)
	ans = 1
	for i in range(n):
		if s[i] not in a:
			if a:
				if a[-1] == s[i - 1]:
					a += s[i]
				elif a[0] == s[i - 1]:
					a = s[i] + a
				else:
					ans = 0
					break
			else:
				a += s[i]
		elif abs(a.find(s[i]) - a.find(s[i - 1])) > 1:
			ans = 0
			break
	if ans:
		print('YES')
		for i in range(26):
			if chr(97 + i) not in a:
				a += chr(97 + i)
		print(a)
	else:
		print('NO')


from collections import Counter

def solution(string):
	construct = string[0]
	ptr = 0
	for c in string[1:]:
		n = len(construct)
		if ptr - 1 >= 0 and construct[ptr - 1] == c:
			ptr -= 1
		elif ptr + 1 < n and construct[ptr + 1] == c:
			ptr += 1
		elif ptr == n - 1:
			construct += c
			ptr += 1
		elif ptr == 0:
			construct = c + construct
		else:
			return None
	C = Counter(construct)
	for c in C:
		if C[c] > 1:
			return None
	letters = 'abcdefghijklmnopqrstuvwxyz'
	included = set(construct)
	for l in letters:
		if l not in included:
			construct += l
	return construct
n = int(input())
for _ in range(n):
	string = input()
	ans = solution(string)
	if ans:
		print('YES')
		print(ans)
	else:
		print('NO')


from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input()
	d = {}
	d1 = {}
	d2 = {}
	d = defaultdict(lambda : [], d)
	m = 'abcdefghijklmnopqrstuvwxyz'
	for i in m:
		d1[i] = 0
		d2[i] = 0
	if len(s) == 1:
		d1[s] = 1
		ans = s[0]
		for i in d1.keys():
			if d1[i] == 0:
				ans += i
		print('YES')
		print(ans)
	else:
		d[s[0]].append(s[1])
		i = 1
		while i < len(s):
			d[s[i]].append(s[i - 1])
			d[s[i - 1]].append(s[i])
			i += 1
		for i in d.keys():
			d[i] = list(set(d[i]))
		ans = ''
		flag = 0
		for i in d.keys():
			d1[i] = 1
			if len(d[i]) > 2:
				flag = 1
				break
			elif ans == '':
				if len(d[i]) == 1:
					ans = d[i][0] + i
				else:
					ans = d[i][0] + i + d[i][1]
			elif len(d[i]) == 1:
				if ans[0] == i:
					if ans[1] != d[i][0]:
						ans = d[i][0] + ans
				elif ans[-1] == i:
					if ans[-2] != d[i][0]:
						ans = ans + d[i][0]
			elif ans[0] == i:
				if ans[1] == d[i][0] or ans[1] == d[i][1]:
					if ans[1] == d[i][0] and d1[d[i][1]] == 0:
						ans = d[i][1] + ans
					elif ans[1] == d[i][1] and d1[d[i][0]] == 0:
						ans = d[i][0] + ans
					else:
						flag = 1
						break
			elif ans[-2] == d[i][0] or ans[-2] == d[i][1]:
				if ans[-2] == d[i][0] and d1[d[i][1]] == 0:
					ans = ans + d[i][1]
				elif ans[-2] == d[i][1] and d1[d[i][0]] == 0:
					ans = ans + d[i][0]
				else:
					flag = 1
					break
		if flag == 1:
			print('NO')
		else:
			print('YES')
			for i in d1.keys():
				if d1[i] == 0:
					ans = ans + i
			print(ans)


from collections import defaultdict
for i in range(int(input())):
	s = input()
	(st, f) = (-1, 0)
	g = defaultdict(set)
	if len(s) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	for i in range(1, len(s)):
		g[s[i - 1]].add(s[i])
		g[s[i]].add(s[i - 1])
		if len(g[s[i]]) > 2 or len(g[s[i - 1]]) > 2:
			f = 1
			break
	for c in g:
		if len(g[c]) == 1:
			st = c
			break
	if st == -1 or f == 1:
		print('NO')
		continue
	ans = [st]
	while 1:
		x = g[st].pop()
		ans.append(x)
		g[x].remove(st)
		if not g[x]:
			break
		st = x
	print('YES')
	for c in 'abcdefghijklmnopqrstuvwxyz':
		if c not in ans:
			ans.append(c)
	print(''.join(ans))


t = int(input())
for case in range(t):
	s = input()
	adjacent = [[] for _ in range(26)]
	if len(s) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	for i in range(1, len(s)):
		if ord(s[i]) - 97 not in adjacent[ord(s[i - 1]) - 97]:
			adjacent[ord(s[i - 1]) - 97].append(ord(s[i]) - 97)
			adjacent[ord(s[i]) - 97].append(ord(s[i - 1]) - 97)
	one_pos = []
	zero_pos = []
	two_pos = []
	b_bit = 0
	for i in range(26):
		if len(adjacent[i]) == 1:
			one_pos.append(i)
		elif len(adjacent[i]) >= 3:
			b_bit = 1
		elif len(adjacent[i]) == 0:
			zero_pos.append(i)
		else:
			two_pos.append(i)
	if b_bit or len(one_pos) % 2 or len(one_pos) == 0:
		print('NO')
		continue
	visit = []
	while len(one_pos) != 0:
		num = one_pos.pop(0)
		if num in visit:
			continue
		visit.append(num)
		while True:
			if adjacent[num][0] not in visit:
				num = adjacent[num][0]
				visit.append(num)
			elif len(adjacent[num]) == 1:
				break
			elif adjacent[num][1] not in visit:
				num = adjacent[num][1]
				visit.append(num)
			else:
				b_bit = 1
				break
	if b_bit:
		print('NO')
	print('YES')
	for i in range(26):
		if i not in visit:
			visit.append(i)
	for i in visit:
		print(chr(i + 97), end='')
	print()


t = int(input())
for zz in range(t):
	s = input()
	lst = [s[0]]
	ci = 0
	ha = True
	for i in range(1, len(s)):
		if s[i] == lst[ci]:
			pass
		elif ci > 0 and lst[ci - 1] == s[i]:
			ci -= 1
		elif ci < len(lst) - 1 and lst[ci + 1] == s[i]:
			ci += 1
		elif ci == len(lst) - 1 and s[i] not in lst:
			lst.append(s[i])
			ci += 1
		elif ci == 0 and s[i] not in lst:
			lst.insert(0, s[i])
		else:
			ha = False
			break
	if not ha:
		print('NO')
	else:
		print('YES')
		d = 'abcdefghijklmnopqrstuvwxyz'
		tt = list(set(d) - set(lst))
		lst += tt
		print(''.join(lst))


q = int(input())
for _ in range(q):
	s = input()
	d = dict()
	f = True
	for i in range(len(s)):
		nkey = s[i + 1] if i != len(s) - 1 else None
		pkey = s[i - 1] if i != 0 else None
		l = d.get(s[i], [])
		if pkey is not None and pkey not in l:
			if len(l) >= 2:
				f = False
				break
			l.append(pkey)
			d[s[i]] = l
			l2 = d.get(pkey, [])
			if s[i] not in l2:
				if len(l2) >= 2:
					f = False
					break
				l2.append(s[i])
				d[pkey] = l2
		if nkey is not None and nkey not in l:
			if len(l) >= 2:
				f = False
				break
			l.append(nkey)
			d[s[i]] = l
			l2 = d.get(nkey, [])
			if s[i] not in l2:
				if len(l2) >= 2:
					f = False
					break
				l2.append(s[i])
				d[nkey] = l2
	s = ''
	for k in d.keys():
		if s == '':
			if len(d[k]) == 0:
				s += k
			elif len(d[k]) == 1:
				s += k + d[k][0]
			elif len(d[k]) == 2:
				s += d[k][0] + k + d[k][1]
		elif s.find(k) == -1:
			ic1 = ic2 = -1
			if len(d[k]) == 1:
				ic1 = s.find(d[k][0])
			elif len(d[k]) == 2:
				ic1 = s.find(d[k][0])
				ic2 = s.find(d[k][1])
			if ic1 != -1 and ic2 != -1:
				f = False
			elif ic1 != -1:
				if ic1 == 0:
					s = k + s
					if len(d[k]) == 2:
						s = d[k][1] + s
				elif ic1 == len(s) - 1:
					s = s + k
					if len(d[k]) == 2:
						s = s + d[k][1]
			elif ic2 != -1:
				if ic2 == 0:
					s = s[k][0] + k + s
				elif ic2 == len(s) - 1:
					s = s + k + s[k][0]
		else:
			ic = s.find(k)
			if ic == 0:
				if len(d[k]) == 2 and s[1] == d[k][0]:
					if d[k][1] in s:
						f = False
					s = d[k][1] + s
				elif len(d[k]) == 2 and s[1] == d[k][1]:
					if d[k][0] in s:
						f = False
					s = d[k][0] + s
				elif len(d[k]) == 2:
					f = False
				elif len(d[k]) == 1 and s[1] == d[k][0]:
					pass
				else:
					f = False
			elif ic == len(s) - 1:
				if len(d[k]) == 2 and s[len(s) - 2] == d[k][0]:
					if d[k][1] in s:
						f = False
					s = s + d[k][1]
				elif len(d[k]) == 2 and s[len(s) - 2] == d[k][1]:
					if d[k][0] in s:
						f = False
					s = s + d[k][0]
				elif len(d[k]) == 2:
					f = False
				elif len(d[k]) == 1 and s[len(s) - 2] == d[k][0]:
					pass
				else:
					f = False
					pass
			elif s[ic - 1] not in d[k] or s[ic + 1] not in d[k]:
				f = False
			else:
				pass
	if f:
		list_lower = ['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']
		for c in list_lower:
			if c not in s:
				s = s + c
		print('YES')
		print(s)
	else:
		print('NO')


from collections import defaultdict
t = int(input())
for i in range(t):
	str_ = input()
	oops = [i for i in str_]
	oops = set(oops)
	dict1 = defaultdict(list)
	if len(str_) <= 3:
		out = list(set(str_))
		outa = ''.join(out)
		for i in range(97, 123):
			if chr(i) not in out:
				outa += chr(i)
		print('YES')
		print(outa)
	elif len(str_) == len(oops):
		outa = ''.join(str_)
		for i in range(97, 123):
			if chr(i) not in outa:
				outa += chr(i)
		print('YES')
		print(outa)
	else:
		for i in range(len(str_)):
			if i - 1 >= 0:
				if str_[i] != str_[i - 1]:
					dict1[str_[i]].append(str_[i - 1])
			if i + 1 <= len(str_) - 1:
				if str_[i] != str_[i + 1]:
					dict1[str_[i]].append(str_[i + 1])
		ok = True
		one = 0
		for i in dict1:
			if len(set(dict1[i])) == 1:
				one += 1
				store = i
			if len(set(dict1[i])) >= 3:
				ok = False
		if one == 0:
			ok = False
		if ok == False:
			print('NO')
		else:
			outp = str()
			outp += store
			visited = set()
			stack = []

			def dfs(graph, start, outp):
				visited.add(start)
				stack.append(start)
				while stack:
					vertex = stack.pop()
					for ij in set(graph[vertex]):
						if ij not in visited:
							outp += ij
							visited.add(ij)
							stack.append(ij)
				return outp
			stringa = dfs(dict1, store, outp)
			for i in range(97, 123):
				if chr(i) not in stringa:
					stringa += chr(i)
			print('YES')
			print(stringa)


n = int(input())
for i in range(n):
	s = input()
	aaaaaa = 'qwertyuioplkjhgfdsazxcvbnm'
	if len(s) == 1:
		print('YES')
		ans = s
		for i in aaaaaa:
			if i not in ans:
				ans += i
		print(ans)
		continue
	d = {}
	alp = ''
	ans = 'YES'
	d[s[0]] = [s[1]]
	if s[-1] not in d:
		d[s[-1]] = [s[-2]]
	else:
		d[s[-1]].append(s[-2])
	start = 'ans'
	dlina = len(set(s))
	for j in range(1, len(s) - 1):
		if not s[j] in d:
			d[s[j]] = [s[j - 1], s[j + 1]]
		else:
			d[s[j]].append(s[j - 1])
			d[s[j]].append(s[j + 1])
	for j in d:
		if len(set(d[j])) >= 3:
			ans = 'NO'
			break
	if ans == 'NO':
		print(ans)
		continue
	else:
		for j in d:
			l = list(set(d[j]))
			for k in l:
				if j not in d[k]:
					ans = 'NO'
					break
			if ans == 'NO':
				break
			if len(l) == 1:
				start = j
		if start == 'ans':
			ans = 'NO'
		if ans == 'NO':
			print('NO')
			continue
		alp = start
		uz = 1
		while True:
			for j in d[start]:
				if j not in alp:
					alp += j
					uz += 1
					start = j
					break
			if uz == dlina:
				break
		for j in 'qwertyuioplkjhgfdsazxcvbnm':
			if j not in alp:
				alp += j
		p = {}
		for j in range(len(alp)):
			p[alp[j]] = j
		for j in range(len(s) - 1):
			if abs(p[s[j]] - p[s[j + 1]]) != 1:
				ans = 'NO'
				break
		if ans == 'NO':
			print(ans)
		else:
			print(ans)
			print(alp)


import math
for _ in range(int(input())):
	s = input()
	key = []
	point = -1
	flag = 0
	for i in s:
		if len(key) < 2:
			key.append(i)
			point += 1
		elif len(key) - 2 >= point and key[point + 1] == i:
			point += 1
		elif point > 0 and key[point - 1] == i:
			point -= 1
		elif point == 0 and i not in key:
			key.insert(0, i)
			point = 0
		elif point == len(key) - 1 and i not in key:
			key.append(i)
			point += 1
		else:
			flag = 1
			break
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	key.reverse()
	if flag == 1:
		print('NO')
	else:
		print('YES')
		for i in alphabet:
			if i not in key:
				key.append(i)
		print(''.join(key))


from collections import defaultdict
import queue

def keyboard(graph, record, valRecord, start):
	q = queue.Queue()
	q.put([start, 0])
	while not q.empty():
		t = q.get()
		(node, o) = (t[0], t[1])
		for i in graph[node]:
			if record.get(i, float('inf')) == float('inf'):
				if valRecord.get(o - 1, float('inf')) == float('inf'):
					record[i] = o - 1
					valRecord[o - 1] = i
					q.put([i, record[i]])
				elif valRecord.get(o + 1, float('inf')) == float('inf'):
					record[i] = o + 1
					valRecord[o + 1] = i
					q.put([i, record[i]])
				else:
					return 0
			elif abs(record[i] - o) != 1:
				return 0
	return 1
for _ in range(int(input())):
	a = list(input())
	n = len(a)
	graph = defaultdict(list)
	for i in range(n - 1):
		(x, y) = (a[i], a[i + 1])
		graph[x].append(y)
		graph[y].append(x)
	start = a[0]
	record = {}
	record[start] = 0
	valRec = {}
	valRec[0] = start
	verdict = keyboard(graph, record, valRec, start)
	if verdict:
		ans = ''
		for i in sorted(valRec.keys()):
			ans += valRec[i]
		for i in ['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']:
			if record.get(i, float('inf')) == float('inf'):
				ans += i
		print('YES')
		print(ans)
	else:
		print('NO')


def solve(s):

	def keys(s):
		res = s[0]
		prev = 0
		for (i, c) in enumerate(s):
			if i == 0:
				continue
			if c not in res:
				if s[i - 1] == res[0]:
					res = c + res
					(cur, prev) = (0, 1)
				elif s[i - 1] == res[-1]:
					res = res + c
					(cur, prev) = (len(res) - 1, len(res) - 2)
				else:
					return False
			else:
				cur = res.index(c)
			if cur - prev not in [-1, 1]:
				return False
			prev = cur
		return res
	ans = keys(s)
	if ans == False:
		print('NO')
	else:
		for i in 'abcdefghijklmnopqrstuvwxyz':
			if i not in ans:
				ans += i
		print('YES')
		print(ans)

def main():
	tc = int(input())
	for _ in range(tc):
		s = input()
		solve(s)
main()


import math
import collections
import functools
import sys
import os
import string

def solve():
	s = input()
	vis = set()
	dp = [''] * 100
	dp[50] = s[0]
	vis.add(s[0])
	f = True
	idx = 50
	(l, r) = (50, 50)
	for i in range(1, len(s)):
		if dp[idx - 1] == s[i]:
			idx -= 1
			l = min(l, l)
			continue
		if dp[idx + 1] == s[i]:
			idx += 1
			r = max(r, idx)
			continue
		if dp[idx + 1] == '':
			idx += 1
			dp[idx] = s[i]
			if s[i] in vis:
				f = False
				break
			vis.add(s[i])
			r = max(r, idx)
			continue
		if dp[idx - 1] == '':
			idx -= 1
			dp[idx] = s[i]
			if s[i] in vis:
				f = False
				break
			vis.add(s[i])
			l = min(l, idx)
			continue
		f = False
		break
	if not f:
		print('NO')
		return
	print('YES')
	for i in range(l, r + 1):
		print(dp[i], sep='', end='')
	for item in string.ascii_lowercase:
		if item in vis:
			continue
		print(item, sep='', end='')
	print()

def main():
	T = 1
	T = int(input())
	while T:
		solve()
		T -= 1
main()


def solve(s):
	l = set(s[0])
	res = [s[0]]
	i = 0
	for j in range(1, len(s)):
		if i + 1 < len(res) and res[i + 1] == s[j]:
			i = i + 1
			continue
		if i - 1 > -1 and res[i - 1] == s[j]:
			i = i - 1
			continue
		if i + 1 < len(res) and i - 1 > -1:
			return ''
		if s[j] in l:
			return ''
		if i == 0:
			res.insert(0, s[j])
			l.add(s[j])
			continue
		if i == len(res) - 1:
			res.append(s[j])
			l.add(s[j])
			i += 1
	res = ''.join(res)
	a = ord('a')
	z = ord('z')
	for i in range(a, z + 1):
		if chr(i) not in l:
			res += chr(i)
	return res
for t in range(int(input())):
	s = input()
	res = solve(s)
	if res:
		print('YES')
		print(res)
	else:
		print('NO')


import string
NTC = int(input())
for _ in range(NTC):
	s = input()
	if len(s) == 1:
		print('YES')
		print(string.ascii_lowercase)
		continue
	adj = {c: set() for c in string.ascii_lowercase}
	for (a, b) in zip(s[:-1], s[1:]):
		adj[a].add(b)
		adj[b].add(a)
	possible = True
	start = None
	for (c, neighs) in adj.items():
		if len(neighs) > 2:
			possible = False
			break
		if len(neighs) == 1:
			start = c
	if not possible or start is None:
		print('NO')
		continue
	keyboard = ''
	cur = start
	while True:
		keyboard += cur
		for neigh in adj[cur]:
			if neigh in keyboard:
				continue
			else:
				cur = neigh
				break
		else:
			break
		if cur == start:
			break
	print('YES')
	for c in string.ascii_lowercase:
		if c not in keyboard:
			keyboard += c
	print(keyboard)


import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	s = [ord(x) - 97 for x in ns()]
	G = [set() for _ in range(26)]
	n = len(s)
	for u in range(n - 1):
		G[s[u]].add(s[u + 1])
		G[s[u + 1]].add(s[u])
	f = [len(x) for x in G]
	use = [0] * 26
	p = list()
	for i in range(26):
		if use[i]:
			continue
		if f[i] <= 1:
			p.append(i)
			use[i] = 1
			while True:
				for x in G[p[-1]]:
					if not use[x]:
						use[x] = 1
						p.append(x)
						break
				else:
					break
	if len(p) != 26:
		print('NO')
		return
	h = [0] * 26
	for i in range(26):
		h[p[i]] = i
	for i in range(n - 1):
		if abs(h[s[i]] - h[s[i + 1]]) > 1:
			print('NO')
			return
	res = [chr(x + 97) for x in p]
	print('YES')
	print(''.join(res))
	return
T = ni()
for _ in range(T):
	solve()


import os
import sys
from io import BytesIO, IOBase
from collections import deque
from string import ascii_lowercase

def solution(s):
	(used, n) = ([False] * 26, len(s))
	used[ord(s[0]) - ord('a')] = True
	res = deque()
	res.append(s[0])
	pos = 0
	for i in range(1, n):
		if used[ord(s[i]) - ord('a')]:
			if pos > 0 and res[pos - 1] == s[i]:
				pos -= 1
			elif pos + 1 < len(res) and res[pos + 1] == s[i]:
				pos += 1
			else:
				write('NO')
				return
		elif pos == 0:
			res.appendleft(s[i])
		elif pos == len(res) - 1:
			res.append(s[i])
			pos += 1
		else:
			write('NO')
			return
		used[ord(s[i]) - ord('a')] = True
	res = ''.join(res)
	rest = ''.join((c for c in ascii_lowercase if c not in res))
	write('YES')
	write(res + rest)

def main():
	for _ in range(r_int()):
		solution(input())
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))

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

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

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

def r_int():
	return int(input())

def p_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


from queue import deque
import string
T = int(input())
answer = ''
for t in range(T):
	s = input()
	n = len(s)
	cursor = 0
	r = 0
	getted = {s[0]: True}
	syms = deque(s[0])
	end = False
	for i in range(1, n):
		if not getted.get(s[i]):
			getted[s[i]] = True
			if cursor == r:
				r += 1
				cursor += 1
				syms.append(s[i])
			elif cursor == 0:
				syms.appendleft(s[i])
				r += 1
			else:
				answer += 'NO\n'
				end = True
				break
		else:
			if cursor == 0:
				if syms[cursor + 1] == s[i]:
					cursor += 1
					continue
				else:
					answer += 'NO\n'
					end = True
					break
			if cursor == r:
				if syms[cursor - 1] == s[i]:
					cursor -= 1
					continue
				else:
					answer += 'NO\n'
					end = True
					break
			if syms[cursor - 1] == s[i]:
				cursor -= 1
				continue
			if syms[cursor + 1] == s[i]:
				cursor += 1
				continue
			answer += 'NO\n'
			end = True
			break
	letters = string.ascii_lowercase
	if not end:
		answer += 'YES\n'
		for sy in syms:
			answer += str(sy)
		for l in letters:
			if not getted.get(l):
				answer += l
		answer += '\n'
print(answer)


import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1 / 0

def write(*args, sep='\n'):
	for i in args:
		sys.stdout.write('{}{}'.format(i, sep))
INF = float('inf')
MOD = int(1000000000.0 + 7)
YES = 'YES'
NO = 'NO'
for _ in range(int(input())):
	try:
		s = input()
		keyboard = [-1] * 100
		cur = 50
		keyboard[cur] = s[0]
		for letter in s[1:]:
			if letter in keyboard:
				if keyboard[cur] != letter and keyboard[cur - 1] != letter and (keyboard[cur + 1] != letter):
					print(NO)
					go()
				if keyboard[cur] == letter:
					continue
				elif keyboard[cur - 1] == letter:
					cur -= 1
				else:
					cur += 1
			elif keyboard[cur + 1] != -1 and keyboard[cur - 1] != -1:
				print(NO)
				go()
			elif keyboard[cur + 1] == -1:
				keyboard[cur + 1] = letter
				cur += 1
			else:
				keyboard[cur - 1] = letter
				cur -= 1
		while keyboard[-1] == -1:
			keyboard.pop()
		while keyboard[0] == -1:
			keyboard.pop(0)
		ans = list(map(str, keyboard))
		for i in 'abcdefghijklmnopqrstuvwxyz':
			if not i in ans:
				ans.append(i)
		print(YES)
		print(*ans, sep='')
	except ZeroDivisionError:
		continue
	except Exception as e:
		print(e)
		continue


def addMore(next, prev):
	if len(R[next]) == 2:
		if R[next][0] in done:
			if R[next][0] != prev:
				return
			elif R[next][1] in done:
				if R[next][1] != prev:
					return
			else:
				done.append(next)
				addMore(R[next][1], next)
		elif R[next][1] in done:
			if R[next][1] != prev:
				return
			done.append(next)
			addMore(R[next][0], next)
	else:
		done.append(next)
for tests in range(int(input())):
	S = input()
	N = len(S)
	R = [[] for i in range(26)]
	np = False
	done = []
	if N == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	for i in range(len(S)):
		pos = ord(S[i]) - 97
		if i > 0 and i < N - 1:
			if ord(S[i - 1]) - 97 not in R[pos]:
				R[pos].append(ord(S[i - 1]) - 97)
			if ord(S[i + 1]) - 97 not in R[pos]:
				R[pos].append(ord(S[i + 1]) - 97)
			if len(R[pos]) > 2:
				np = True
				break
		elif i == 0 and i != N - 1:
			if ord(S[i + 1]) - 97 not in R[pos]:
				R[pos].append(ord(S[i + 1]) - 97)
			if len(R[pos]) > 2:
				np = True
				break
		elif i == N - 1 and i != 0:
			if ord(S[i - 1]) - 97 not in R[pos]:
				R[pos].append(ord(S[i - 1]) - 97)
			if len(R[pos]) > 2:
				np = True
				break
	if np:
		print('NO')
		continue
	for adj in range(len(R)):
		if len(R[adj]) == 1:
			break
	if adj == len(R):
		print('NO')
		continue
	if len(R[adj]) != 1:
		print('NO')
		continue
	done.append(adj)
	addMore(R[adj][0], adj)
	N = 0
	dont = [False] * 26
	for i in range(len(R)):
		if len(R[i]) != 0:
			N += 1
			dont[i] = True
	if len(done) != N:
		print('NO')
		continue
	else:
		print('YES')
		for i in done:
			print(chr(i + 97), end='')
		for i in range(26):
			if not dont[i]:
				print(chr(i + 97), end='')
		print('')


from collections import Counter
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')
(t,) = gil()
for _ in range(t):
	s = g()
	n = len(s)
	graph = {}
	flag = True
	for i in range(n):
		if s[i] not in graph:
			graph[s[i]] = set()
		if i:
			graph[s[i]].add(s[i - 1])
		if i + 1 < n:
			graph[s[i]].add(s[i + 1])
		if len(graph[s[i]]) > 2:
			flag = False
	if n == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
	elif flag:
		for ch in graph:
			if len(graph[ch]) == 1:
				break
		if len(graph[ch]) == 1:
			print('YES')
			ans = [ch]
			l = 1
			while len(ans) == l:
				for ch in graph[ans[-1]]:
					if ch not in ans:
						ans.append(ch)
						break
				l += 1
			for ch in 'abcdefghijklmnopqrstuvwxyz':
				if ch not in ans:
					ans.append(ch)
			print(''.join(ans))
		else:
			print('NO')
	else:
		print('NO')


import sys
from string import ascii_lowercase as alps
t = int(sys.stdin.readline().rstrip())

def main():
	for _ in range(t):
		s = '$' + sys.stdin.readline().rstrip()
		fixed = set()
		l = len(s)
		for i in range(1, l):
			c = s[i]
			d = s[i - 1]
			if c in fixed:
				j = res.index(d)
				flag = False
				if j == 0:
					if res[j + 1] == c:
						flag = True
				elif j < len(res) - 1:
					if res[j - 1] == c or res[j + 1] == c:
						flag = True
				elif res[j - 1] == c:
					flag = True
				if not flag:
					yield 'NO'
					break
			else:
				if i == 1:
					res = c
				elif i == 2:
					res += c
				else:
					j = res.index(d)
					if j == 0:
						res = c + res
					elif j == len(res) - 1:
						res += c
					else:
						yield 'NO'
						break
				fixed.add(c)
		else:
			yield 'YES'
			no_used = set(alps) - set(res)
			res = res + ''.join(sorted(no_used))
			yield res
ans = main()
print(*ans, sep='\n')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input()[:-1]
	vals = [ord(char) - 97 for char in s]
	n = 26
	graph = [set() for i in range(n)]
	for i in range(len(vals) - 1):
		v = vals[i]
		u = vals[i + 1]
		graph[v].add(u)
		graph[u].add(v)
	no_flag = False
	for u in range(26):
		if len(graph[u]) > 2:
			no_flag = True
	if no_flag:
		print('NO')
		continue
	used = [False] * 26
	ans = []
	for v in range(26):
		if used[v]:
			continue
		if len(graph[v]) == 0:
			ans.append(chr(v + 97))
			used[v] = True
		elif len(graph[v]) == 1:
			ans.append(chr(v + 97))
			used[v] = True
			stack = [v]
			while stack:
				v = stack.pop()
				for nxt_v in graph[v]:
					if used[nxt_v]:
						continue
					used[nxt_v] = True
					stack.append(nxt_v)
					ans.append(chr(nxt_v + 97))
	if len(ans) == 26:
		print('YES')
		print(''.join(ans))
	else:
		print('NO')


N = int(input())
for _ in range(N):
	s = input()
	if len(s) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	es = [set() for _ in range(26)]
	for (a, b) in zip(s, s[1:]):
		i = ord(a) - ord('a')
		j = ord(b) - ord('a')
		es[i].add(j)
		es[j].add(i)
	if any((len(e) > 2 for e in es)):
		print('NO')
		continue
	if len([1 for e in es if len(e) == 1]) != 2:
		print('NO')
		continue
	ans = []
	for (i, e) in enumerate(es):
		if len(e) == 1:
			ans = [i, list(e)[0]]
			break
	invalid = False
	while len(es[ans[-1]]) == 2:
		(a, b) = es[ans[-1]]
		if a == ans[-2]:
			if b in ans:
				invalid = True
			ans.append(b)
		else:
			if a in ans:
				invalid = True
			ans.append(a)
		if invalid:
			break
	for i in range(26):
		if i in ans:
			continue
		if es[i]:
			invalid = True
		ans.append(i)
	if invalid:
		print('NO')
		continue
	print('YES')
	print(''.join([chr(i + ord('a')) for i in ans]))


for _ in range(int(input())):
	s = list(input())[::-1]
	t = s.pop()
	i = 0
	while s:
		x = s.pop()
		if x in t:
			if i and t[i - 1] == x:
				i -= 1
			elif i + 1 < len(t) and t[i + 1] == x:
				i += 1
			else:
				print('NO')
				break
		elif i + 1 >= len(t):
			t += x
			i += 1
		elif not i:
			t = x + t
		else:
			print('NO')
			break
	else:
		print('YES')
		for x in 'abcdefghijklmnopqrstuvwxyz':
			if x not in t:
				t += x
		print(t)


t = int(input())

def alpha(e, u):
	p = -1
	sol = ''
	used = [False for i in range(26)]
	while True:
		used[u] = True
		sol += chr(u + ord('a'))
		for i in range(26):
			if e[u][i] and i != p:
				p = u
				u = i
				break
		else:
			break
	for i in range(26):
		if not used[i]:
			sol += chr(i + ord('a'))
	return sol
for tc in range(t):
	w = input()
	s = set(list(w))
	e = [[0 for i in range(26)] for j in range(26)]
	for i in range(len(w) - 1):
		u = ord(w[i]) - ord('a')
		v = ord(w[i + 1]) - ord('a')
		e[u][v] = e[v][u] = 1
	if len(w) == 1:
		print('YES')
		print(alpha(e, 0))
		continue
	deg = [sum(e[u]) for u in range(26)]
	if deg.count(1) != 2 or deg.count(1) + deg.count(2) != len(s):
		print('NO')
	else:
		print('YES')
		print(alpha(e, deg.index(1)))


from collections import defaultdict, Counter

def graph(s):
	dic = defaultdict(lambda : set())
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			dic[s[i]].add(s[i + 1])
			dic[s[i + 1]].add(s[i])
	return dic
for _ in range(int(input())):
	s = input()
	cnt = Counter('abcdefghijklmnopqrstuvwxyz')
	if len(s) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	gp = graph(s)
	root = None
	poss = True
	for i in gp:
		if len(gp[i]) == 1:
			root = i
		if len(gp[i]) > 2:
			poss = False
			break
	if poss:
		if root == None:
			print('NO')
		else:
			ans = ''
			while True:
				ans += root
				cnt[root] -= 1
				for nei in list(gp[root]):
					gp[nei].remove(root)
				temp = list(gp[root])
				if len(temp) == 0:
					break
				gp.pop(root)
				root = temp[0]
			for i in cnt:
				if cnt[i] > 0:
					ans += i
			print('YES')
			print(ans)
	else:
		print('NO')


import sys
import math
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
for _ in range(int(input())):
	s = input()
	flag = True
	mark = [0] * 26
	ans = ''
	l = -1
	r = -1
	for i in range(len(s)):
		if mark[ord(s[i]) - 97] == 0:
			if len(ans) == 0:
				ans += s[i]
				l = ord(s[i])
				r = ord(s[i])
				mark[ord(s[i]) - 97] = 1
			else:
				if ord(s[i - 1]) == l:
					ans = s[i] + ans
					l = ord(s[i])
				elif ord(s[i - 1]) == r:
					ans = ans + s[i]
					r = ord(s[i])
				else:
					flag = False
					break
				mark[ord(s[i]) - 97] = 1
		else:
			for j in range(len(ans)):
				if ans[j] == s[i]:
					if j - 1 >= 0 and ans[j - 1] == s[i - 1] or (j + 1 < len(ans) and ans[j + 1] == s[i - 1]):
						continue
					else:
						flag = False
						break
	if flag is False:
		print('NO')
	else:
		for i in range(26):
			if mark[i] == 0:
				ans += chr(i + 97)
		print('YES')
		print(ans)


import collections, string
for _ in range(int(input())):
	s = list(input())
	vis = set()
	d = collections.defaultdict(int)
	g = collections.defaultdict(list)
	for i in range(1, len(s)):
		t = sorted(s[i - 1:i + 1])
		c = ''.join(t)
		if c in vis:
			continue
		else:
			vis.add(c)
			d[t[0]] += 1
			d[t[1]] += 1
			g[t[0]].append(t[1])
			g[t[1]].append(t[0])
	ans = [0] * len(d)
	(i, j) = (0, len(d) - 1)
	q = [x for x in d.keys() if d[x] == 1]
	while q:
		if len(q) > 2:
			break
		if len(q) == 1:
			ans[i] = q[0]
			i += 1
			break
		ans[i] = q[0]
		i += 1
		ans[j] = q[1]
		j -= 1
		for _ in range(2):
			cur = q.pop(0)
			for x in g[cur]:
				d[x] -= 1
				if d[x] == 1:
					q.append(x)
	if i < j:
		print('NO')
	else:
		print('YES')
		for c in string.ascii_lowercase:
			if c not in ans:
				ans.append(c)
		print(''.join(ans))


import string

def continuous(s):
	d1 = {s[0]: 1}
	d2 = {1: s[0]}
	l = [s[0]]
	for i in range(len(s) - 1):
		a = s[i]
		b = s[i + 1]
		v1 = d1.get(a)
		v2 = d1.get(b)
		if v2 is None:
			if d2.get(v1 + 1) is not None:
				if d2.get(v1 - 1) is not None:
					return ('NO', 0)
				d1[b] = v1 - 1
				d2[v1 - 1] = b
				l.insert(0, b)
			else:
				d1[b] = v1 + 1
				d2[v1 + 1] = b
				l.append(b)
		elif abs(v1 - v2) != 1:
			return ('NO', 0)
	st = string.ascii_lowercase
	s = ''.join(l)
	for e in st:
		if e not in l:
			s += e
	return ('YES', s)
n = int(input())
for _ in range(n):
	(a, b) = continuous(input())
	print(a)
	if b:
		print(b)


import sys
from collections import deque
alf = set(list('qwertyuiopasdfghjklzxcvbnm'))
input = lambda : sys.stdin.readline().strip()
for i in range(int(input())):
	s = input()
	ans = deque()
	used = set([s[0]])
	ans.append(s[0])
	f = False
	ind = 0
	for i in range(len(s) - 1):
		if s[i + 1] in used:
			if ind == 0:
				if ans[1] == s[i + 1]:
					ind = 1
				else:
					f = True
					break
			elif ind == len(ans) - 1:
				if ans[ind - 1] == s[i + 1]:
					ind -= 1
				else:
					f = True
					break
			elif ans[ind - 1] == s[i + 1]:
				ind -= 1
			elif ans[ind + 1] == s[i + 1]:
				ind += 1
			else:
				f = True
				break
		else:
			used.add(s[i + 1])
			if ind == 0:
				ans.appendleft(s[i + 1])
			elif ind == len(ans) - 1:
				ans.append(s[i + 1])
				ind += 1
			else:
				f = True
				break
	if f:
		print('NO')
	else:
		print('YES')
		print(''.join(ans) + ''.join(list(alf - set(ans))))


import sys
readline = sys.stdin.readline
T = int(readline())
Ans = []
for qu in range(T):
	S = list(map(lambda x: ord(x) - 97, readline().strip()))
	N = len(S)
	inf = 50
	val = [inf] * 26
	val[S[0]] = 0
	plus = False
	for i in range(1, N):
		s = S[i]
		if val[s] == inf:
			if val[S[i - 1]] < 0 or (val[S[i - 1]] == 0 and plus):
				val[s] = val[S[i - 1]] - 1
			else:
				plus = True
				val[s] = val[S[i - 1]] + 1
	st = list(range(26))
	st.sort(key=lambda x: val[x])
	vt = [None] * 26
	for i in range(26):
		vt[st[i]] = i
	for i in range(1, N):
		if abs(vt[S[i - 1]] - vt[S[i]]) != 1:
			break
	else:
		Ans.append('YES')
		Ans.append(''.join(map(lambda x: chr(x + 97), st)))
		continue
	Ans.append('NO')
print('\n'.join(map(str, Ans)))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def keyboard():
	for _ in range(t):
		string = input()
		strcoll = ['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']
		res = []
		res += [string[0]]
		strcoll.remove(string[0])
		n = len(string)
		currpos = 1
		resok = True
		if n == 1:
			resok = True
		elif string[1] == res[0]:
			resok = False
		else:
			res += string[1]
			strcoll.remove(string[1])
			for i in range(n - 2):
				currlen = len(res)
				if currpos == 0:
					if res[currpos + 1] == string[i + 2]:
						currpos += 1
					elif string[i + 2] in strcoll:
						res = [string[i + 2]] + res
						strcoll.remove(string[i + 2])
						currpos = 0
					else:
						resok = False
						break
				elif currpos + 1 == currlen:
					if res[currpos - 1] == string[i + 2]:
						currpos -= 1
					elif string[i + 2] in strcoll:
						res = res + [string[i + 2]]
						strcoll.remove(string[i + 2])
						currpos += 1
					else:
						resok = False
						break
				elif res[currpos + 1] == string[i + 2]:
					currpos += 1
				elif res[currpos - 1] == string[i + 2]:
					currpos -= 1
				else:
					resok = False
					break
		result = res + strcoll
		if resok:
			yield 'YES'
			yield ''.join(result)
		else:
			yield 'NO'
t = int(input())
ans = keyboard()
print(*ans, sep='\n')


(vis, w) = ({}, {})

def dfs(u, pre):
	global vis
	global w
	ans = 0
	w[u] = 1
	for i in vis[u]:
		if i != pre and i in w:
			return 1
		elif i not in w:
			ans = max(ans, dfs(i, u))
	return ans

def out(u, pre):
	global vis
	print(u, end='')
	for i in vis[u]:
		if i != pre:
			out(i, u)
	return
test = int(input(''))
while test:
	test -= 1
	s = input('')
	vis = {}
	l = len(s)
	for i in range(l):
		if i != 0 and i != l - 1:
			(a, b, c) = (s[i - 1], s[i], s[i + 1])
			if a not in vis.get(b, []):
				vis[b] = vis.get(b, []) + [a]
			if b not in vis.get(a, []):
				vis[a] = vis.get(a, []) + [b]
			if b not in vis.get(c, []):
				vis[c] = vis.get(c, []) + [b]
			if c not in vis.get(b, []):
				vis[b] = vis.get(b, []) + [c]
	flag = 0
	for x in vis:
		if len(vis[x]) > 2:
			flag = 1
		if flag == 1:
			break
		w = {}
		flag = dfs(x, -1)
	if flag == 1:
		print('NO')
	else:
		print('YES')
		start = -1
		for i in vis:
			if len(vis[i]) == 1:
				start = i
				break
		if start != -1:
			out(start, -1)
		else:
			for i in s:
				vis[i] = 1
			print(s, end='')
		for i in range(97, 123):
			x = chr(i)
			if x not in vis:
				print(x, end='')
		print()


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

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

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

def instr():
	s = input()
	return list(s[:len(s)])

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

def dfs(u):
	visited[u] = True
	for v in a[u]:
		if not visited[v]:
			dfs(v)
	res.append(chr(u + 97))

def bfs(source):
	visited = [False] * 26
	Q = []
	Q.append(source)
	visited[source] = True
	last = source
	while len(Q) > 0:
		u = Q.pop(0)
		last = u
		for v in a[u]:
			if not visited[v]:
				Q.append(v)
				visited[v] = True
	return last

def isValid(res, s):
	for i in range(1, len(s)):
		d = abs(res.index(s[i]) - res.index(s[i - 1]))
		if d != 1:
			return False
	return True
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = inp()
res = []
for _ in range(t):
	s = input()
	a = defaultdict(lambda : [])
	n = len(s)
	for i in range(1, n):
		x = ord(s[i - 1]) - 97
		y = ord(s[i]) - 97
		a[x].append(y)
		a[y].append(x)
	visited = [False] * 26
	res = []
	source = bfs(ord(s[0]) - 97)
	dfs(source)
	if isValid(res, s):
		print('YES')
		for k in res:
			print(k, end='')
		for i in range(26):
			if not visited[i]:
				print(chr(i + 97), end='')
		print()
	else:
		print('NO')


from sys import stdin, stdout
import collections, heapq, bisect, math
input = stdin.readline

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

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

def rlstr():
	return list(input().strip().split())

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

def main():
	s = rstr()
	res = s[0]
	visit = [False] * 26
	visit[ord(s[0]) - ord('a')] = True
	start = 0
	d = 1
	for i in range(1, len(s)):
		ind = ord(s[i]) - ord('a')
		if visit[ind]:
			if start - 1 >= 0 and res[start - 1] == s[i]:
				d = -1
			elif start + 1 < len(res) and res[start + 1] == s[i]:
				d = 1
			else:
				return (False, '')
		elif start != 0 and start != len(res) - 1:
			return (False, '')
		else:
			if d > 0:
				res += s[i]
			else:
				res = s[i] + res
			visit[ind] = True
		start += d
		if start < 0:
			start = 0
	for i in range(26):
		if not visit[i]:
			res += chr(ord('a') + i)
	return (True, res)
for _ in range(rint()):
	(res, s) = main()
	if res:
		print('YES')
		print(s)
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	allc = 'qwertyuiopasdfghjklzxcvbnm'
	newstr = s[0] + ''
	allc = allc.replace(s[0], '')
	count = 0
	flag = True
	s = s[1:]
	for cc in s:
		if count > 0 and len(newstr) >= count + 2:
			if newstr[count - 1] == cc:
				count = count - 1
				continue
			elif newstr[count + 1] == cc:
				count = count + 1
				continue
			else:
				print('NO')
				flag = False
				break
		elif count > 0:
			if newstr[count - 1] == cc:
				count = count - 1
				continue
			else:
				if newstr.find(cc) != -1:
					print('NO')
					flag = False
					break
				newstr = newstr + '' + cc
				allc = allc.replace(cc, '')
				count = count + 1
				continue
		elif len(newstr) >= count + 2:
			if newstr[count + 1] == cc:
				count = count + 1
				continue
			else:
				if newstr.find(cc) != -1:
					print('NO')
					flag = False
					break
				newstr = cc + '' + newstr
				allc = allc.replace(cc, '')
				continue
		else:
			newstr = cc + '' + newstr
			allc = allc.replace(cc, '')
			continue
	if flag:
		print('YES')
		print(newstr + allc)


for _ in range(int(input())):
	s = input()
	finish = ''
	x = ['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']
	y = [0] * 52
	u = 26
	d = len(s)
	ok = True
	s1 = list(s)
	for i in range(d):
		if s1[i] in x:
			x.remove(s1[i])
		if y[u - 1] == s1[i]:
			u -= 1
		elif y[u + 1] == s1[i]:
			u += 1
		elif y[u - 1] == 0:
			u -= 1
			if s1[i] in y:
				finish += 'NO'
				ok = False
				break
			else:
				y[u] = s1[i]
		elif y[u + 1] == 0:
			u += 1
			if s1[i] in y:
				finish += 'NO'
				ok = False
				break
			else:
				y[u] = s1[i]
		else:
			finish += 'NO'
			ok = False
			break
	if ok:
		finish += 'YES\n'
		for i in range(52):
			if y[i] != 0:
				finish += y[i]
		for i in range(len(x)):
			finish += x[i]
	print(finish)


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 = int(input())
for _ in range(t):
	i = input()
	s = set(i)
	k = list(s)
	m = 0
	l = []
	if len(i) == 1:
		al.remove(i)
		print('YES')
		print(i + ''.join(al))
		continue
	for y in s:
		a = set()
		for x in range(len(i)):
			if x == 0 and i[x] == y:
				a.add(i[x + 1])
			elif x == len(i) - 1 and i[x] == y:
				a.add(i[x - 1])
			elif i[x] == y:
				a.add(i[x + 1])
				a.add(i[x - 1])
		l.append(list(a))
	f = ''
	if all((len(e) >= 2 for e in l)):
		print('NO')
		continue
	for e in l:
		if len(e) > 2:
			print('NO')
			m += 1
			break
	if m == 1:
		continue
	for q in range(len(s)):
		if len(l[q]) == 1:
			f = f + k[q] + l[q][0]
			while len(f) < len(s):
				for u in range(len(s)):
					if k[u] == f[len(f) - 1]:
						for j in l[u]:
							if j not in f:
								f = f + j
			m += 1
		if m == 1:
			break
	new = []
	for h in al:
		if h not in f:
			new.append(h)
	f = f + ''.join(new)
	if len(f) != 26:
		f = f + 'e'
	print('YES')
	print(f)


import sys, math
MOD = 998244353
alpha = {chr(x) for x in range(97, 97 + 26)}
for test_num in range(int(input())):
	s = input()
	ans = [s[0]]
	ans_set = {s[0]}
	j = 0
	poss = True
	for i in range(1, len(s)):
		if s[i] in ans_set:
			if ans[j] == s[i]:
				continue
			elif 0 <= j - 1 and ans[j - 1] == s[i]:
				j -= 1
			elif j + 1 < len(ans) and ans[j + 1] == s[i]:
				j += 1
			else:
				poss = False
				break
		else:
			ans_set.add(s[i])
			if j + 1 == len(ans) and ans[j] == s[i - 1]:
				ans.append(s[i])
				j += 1
			elif j == 0 and ans[j] == s[i - 1]:
				ans = [s[i]] + ans
			else:
				poss = False
				break
	for c in alpha:
		if c not in ans_set:
			ans.append(c)
	ans = ''.join(ans)
	if poss:
		print('YES')
		print(ans)
	else:
		print('NO')


t = int(input())
alp = list('abcdefghijklmnopqrstuvwxyz')
for ii in range(t):
	s = input()
	ss = set(s)
	flag = 0
	d = {}
	for i in ss:
		d[i] = []
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			flag = 1
			break
		else:
			if s[i - 1] not in d[s[i]]:
				d[s[i]] = d[s[i]] + [s[i - 1]]
			if s[i] not in d[s[i - 1]]:
				d[s[i - 1]] = d[s[i - 1]] + [s[i]]
	xx = ''
	xxx = ''
	if flag == 0:
		c = 0
		flag2 = 1
		for i in ss:
			if len(d[i]) > 2:
				flag2 = 0
				break
			elif len(d[i]) == 1:
				c = c + 1
				xx = d[i][0]
				xxx = i
		if (c != 2 or flag2 == 0) and len(s) > 1:
			print('NO')
		elif (c != 2 or flag2 == 0) and len(s) == 1:
			print('YES')
			ans = s
			for i in alp:
				if i != s:
					ans = ans + i
			print(ans)
		else:
			print('YES')
			ls = []
			ls.append(xxx)
			while 1:
				if len(xx) == 1:
					ls.append(xx[0])
					xx = d[xx[0]]
				elif xx[0] not in ls:
					ls.append(xx[0])
					xx = d[xx[0]]
				elif xx[1] not in ls:
					ls.append(xx[1])
					xx = d[xx[1]]
				if len(ls) == len(ss):
					break
			ls2 = []
			for kk in alp:
				if kk not in ls:
					ls2.append(kk)
			ls3 = ls + ls2
			ans = ''
			for an in ls3:
				ans = ans + an
			print(ans)
	else:
		print('NO')


def binarySearch(arr, x):
	l = 0
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
from math import *

def ceil(a, b):
	if a % b == 0:
		return int(a / b)
	else:
		return a // b + 1
for __ in range(int(input())):
	s = input()
	h = [0] * 26
	ans = s[0]
	h[ord(s[0]) - 97] = 1
	e = True
	x = 0
	for i in range(1, len(s)):
		if i == 1:
			ans += s[i]
			h[ord(s[i]) - 97] = 1
			x += 1
		elif x == len(ans) - 1:
			if s[i] == ans[x - 1]:
				x -= 1
			elif h[ord(s[i]) - 97] == 1:
				e = False
				break
			else:
				ans += s[i]
				h[ord(s[i]) - 97] = 1
				x += 1
		elif x == 0:
			if s[i] == ans[x + 1]:
				x += 1
			elif h[ord(s[i]) - 97] == 1:
				e = False
				break
			else:
				ans = s[i] + ans
				h[ord(s[i]) - 97] = 1
		elif s[i] == ans[x + 1]:
			x += 1
		elif s[i] == ans[x - 1]:
			x -= 1
		else:
			e = False
			break
	if e == False:
		print('NO')
	else:
		print('YES')
		for i in range(26):
			if h[i] == 0:
				ans += chr(i + 97)
		print(ans)


def I():
	return list(map(int, input().split()))
for __ in range(int(input())):
	s = input()
	finalstr = ''
	n = len(s)
	f = 0
	for i in range(n):
		if not s[i] in finalstr:
			if i != 0:
				idx = finalstr.find(s[i - 1])
				if idx == 0:
					finalstr = s[i] + finalstr
				elif idx == len(finalstr) - 1:
					finalstr += s[i]
				else:
					f = 1
					break
			else:
				finalstr += s[i]
		else:
			idx1 = finalstr.find(s[i])
			idx2 = finalstr.find(s[i - 1])
			if abs(idx1 - idx2) > 1:
				f = 1
				break
	if f == 1:
		print('NO')
	else:
		print('YES')
		for i in range(26):
			if chr(97 + i) not in finalstr:
				finalstr += chr(97 + i)
		print(finalstr)


from collections import defaultdict

def dfs(node, parent):
	global res
	visited[node] = 1
	res.append(node)
	for child in adj_list[node]:
		if visited[child] == 1:
			if child != parent:
				return True
		else:
			return dfs(child, node)
	return False
t = int(input())
for _ in range(t):
	s = input()
	l = len(s)
	adj_list = defaultdict(list)
	visited = defaultdict(int)
	res = []
	node = '*'
	for i in range(l):
		if i - 1 > 0:
			if s[i - 1] not in adj_list[s[i]]:
				adj_list[s[i]].append(s[i - 1])
			if s[i] not in adj_list[s[i - 1]]:
				adj_list[s[i - 1]].append(s[i])
		if i + 1 < l:
			if s[i + 1] not in adj_list[s[i]]:
				adj_list[s[i]].append(s[i + 1])
			if s[i] not in adj_list[s[i - 1]]:
				adj_list[s[i + 1]].append(s[i])
	for i in adj_list:
		if len(adj_list[i]) == 1:
			node = i
	if node == '*':
		if len(s) == 1:
			print('YES')
			print('abcdefghijklmnopqrstuvwxyz')
		else:
			print('NO')
	else:
		temp = dfs(node, node)
		flag = 0
		if temp is False:
			for i in adj_list:
				if visited[i] == 0:
					flag = 1
					break
			if flag:
				print('NO')
			else:
				res1 = ''
				x = 'abcdefghijklmnopqrstuvwxyz'
				for i in x:
					if i not in res:
						res1 += i
				print('YES')
				print(''.join(res) + res1)
		else:
			print('NO')


def dfs(node):
	vis[node] = 1
	ans.append(chr(97 + node))
	for j in edge[node]:
		if vis[j] == 0:
			dfs(j)
t = int(input())
for _ in range(t):
	s = str(input())
	n = len(s)
	if n == 1:
		print('YES')
		print('abcdefghijlkmnopqrstuvwxyz')
	else:
		edge = [[] for i in range(26)]
		matrix = [[0] * 26 for i in range(26)]
		for i in range(n - 1):
			matrix[ord(s[i]) - 97][ord(s[i + 1]) - 97] = 1
			matrix[ord(s[i + 1]) - 97][ord(s[i]) - 97] = 1
			edge[ord(s[i]) - 97].append(ord(s[i + 1]) - 97)
			edge[ord(s[i + 1]) - 97].append(ord(s[i]) - 97)
		lis = []
		for i in range(26):
			lis.append(matrix[i].count(1))
		a = max(lis)
		b = lis.count(1)
		if a > 2 or b != 2:
			print('NO')
		else:
			c = lis.index(1)
			ans = []
			vis = [0] * 26
			dfs(c)
			answer = ''
			l = len(ans)
			for i in range(l):
				answer += ans[i]
			for i in range(26):
				if vis[i] == 0:
					answer += chr(97 + i)
			print('YES')
			print(answer)


def solve(s):
	kb = ''
	st = set()
	al = set('qwertyuiopasdfghjklzxcvbnm')
	p = -1
	l = 0
	for i in s:
		if i not in st:
			if p == l - 1:
				st.add(i)
				kb += i
				p += 1
				l += 1
			elif p == 0:
				st.add(i)
				kb = i + kb
				l += 1
			else:
				return 'NO'
		else:
			if kb[p] == i:
				continue
			if p > 0:
				if kb[p - 1] == i:
					p -= 1
					continue
			if p < l - 1:
				if kb[p + 1] == i:
					p += 1
					continue
			return 'NO'
	for i in al:
		if i not in kb:
			kb += i
	return 'YES\n' + kb

def main():
	t = int(input())
	for i in range(t):
		print(solve(input()))
main()


import math
for _ in range(int(input())):
	string = input()
	keyboard = ['' for i in range(3 * 26)]
	idx_of_char = {ele: None for ele in 'qwertyuiopasdfghjklzxcvbnm'}
	idx_of_char[string[0]] = 26
	keyboard[26] = string[0]
	possible = True
	for (i, char) in enumerate(string[1:], 1):
		prev_idx = idx_of_char[string[i - 1]]
		if idx_of_char[char] is not None:
			if keyboard[prev_idx - 1] != char and keyboard[prev_idx + 1] != char:
				possible = False
				break
			else:
				continue
		elif keyboard[prev_idx - 1] == '':
			keyboard[prev_idx - 1] = char
			idx_of_char[char] = prev_idx - 1
		elif keyboard[prev_idx + 1] == '':
			keyboard[prev_idx + 1] = char
			idx_of_char[char] = prev_idx + 1
		else:
			possible = False
			break
	if not possible:
		print('NO')
	else:
		print('YES')
		ans = []
		for ele in keyboard:
			if ele != '':
				ans.append(ele)
		for ele in 'qwertyuiopasdfghjklzxcvbnm':
			if ele not in ans:
				ans.append(ele)
		print(*ans, sep='')


t = int(input())
all = 'abcdefghijklmnopqrstuvwxyz'
for i in range(t):
	s = input()
	if len(s) == 1:
		print('YES')
		print(all)
		continue
	dp = [''] * 60
	dp[30] = s[0]
	now = 30
	for j in range(1, len(s)):
		if s[j] != dp[now + 1] and s[j] != dp[now - 1]:
			if dp[now + 1] == '' and s[j] not in dp:
				dp[now + 1] = s[j]
				now += 1
			elif dp[now - 1] == '' and s[j] not in dp:
				dp[now - 1] = s[j]
				now -= 1
			else:
				print('NO')
				break
		elif s[j] == dp[now]:
			pass
		elif s[j] == dp[now + 1]:
			now += 1
		else:
			now -= 1
		if j + 1 == len(s):
			print('YES')
			for z in dp:
				if z != '':
					print(z, end='')
			for z in all:
				if z not in dp:
					print(z, end='')
			print()


T = int(input())

def solve(S):
	res = [S[0]]
	pos = 0
	for s in S[1:]:
		if 0 <= pos - 1 < len(res) and res[pos - 1] == s:
			pos = pos - 1
		elif 0 <= pos + 1 < len(res) and res[pos + 1] == s:
			pos = pos + 1
		elif pos == 0 and s not in res:
			res.insert(0, s)
		elif pos == len(res) - 1 and s not in res:
			res.append(s)
			pos += 1
		else:
			return None
	for x in range(ord('a'), ord('z') + 1):
		x = chr(x)
		if x not in res:
			res.append(x)
	return ''.join(res)
for _ in range(T):
	res = solve(input())
	if res is None:
		print('NO')
	else:
		print('YES')
		print(res)


def hasloop(gg, src, done, par):
	if done[src]:
		return True
	done[src] = True
	loop = False
	for val in gg[src]:
		if val != par:
			loop = loop or hasloop(gg, val, done, src)
	return loop

def getpath(gg, src, ans, par, done):
	done[src] = True
	for val in gg[src]:
		if val != par:
			getpath(gg, val, ans, src, done)
	ans.append(chr(src + ord('a')))
timer = 1

def dfs(gg, src, par, time):
	global timer
	time[src] = timer
	timer += 1
	for val in gg[src]:
		if val != par:
			dfs(gg, val, src, time)

def mothervertex(gg, src):
	time = [0] * 26
	dfs(gg, src, src, time)
	mv = -1
	ans = -1
	for (ind, val) in enumerate(time):
		if val > ans:
			ans = val
			mv = ind
	return mv
for _ in range(int(input())):
	ss = input()
	gg = [set() for i in range(27)]
	src = -1
	for i in range(len(ss)):
		if i - 1 >= 0 and i + 1 < len(ss):
			gg[ord(ss[i]) - ord('a')].add(ord(ss[i - 1]) - ord('a'))
			gg[ord(ss[i]) - ord('a')].add(ord(ss[i + 1]) - ord('a'))
		elif i - 1 >= 0:
			gg[ord(ss[i]) - ord('a')].add(ord(ss[i - 1]) - ord('a'))
		elif i + 1 < len(ss):
			gg[ord(ss[i]) - ord('a')].add(ord(ss[i + 1]) - ord('a'))
	ans = True
	for edge in gg:
		if len(set(edge)) > 2:
			ans = False
			break
	if ans is False:
		print('NO')
		continue
	done = [False] * 26
	loop = False
	for i in range(26):
		if done[i] == False:
			loop = loop or hasloop(gg, i, done, i)
	if loop:
		print('NO')
		continue
	print('YES')
	ans = []
	done = [False] * 26
	for i in range(26):
		if not done[i]:
			mv = mothervertex(gg, i)
			getpath(gg, mv, ans, mv, done)
	for val in ans:
		print(val, end='')
	print()


import sys
input = sys.stdin.readline
from collections import deque
INF = 10 ** 13
Alp = [chr(i) for i in range(97, 97 + 26)]
N = int(input())
Ss = [list(input().rstrip()) for _ in range(N)]
for S in Ss:
	ok = True
	defined = [False] * 26
	q1 = [S[0]]
	q2 = [S[0]]
	defined[ord(S[0]) - 97] = True
	now = 0
	for s in S[1:]:
		i = ord(s) - 97
		if not defined[i]:
			if now == len(q1) - 1:
				q1.append(s)
				defined[i] = True
				now += 1
			elif now == -len(q2) + 1:
				q2.append(s)
				defined[i] = True
				now -= 1
			else:
				ok = False
				break
		elif now > 0:
			if q1[now - 1] == s:
				now -= 1
			elif now != len(q1) - 1 and q1[now + 1] == s:
				now += 1
			else:
				ok = False
				break
		elif now < 0:
			if q2[-now - 1] == s:
				now += 1
			elif now != -len(q2) + 1 and q2[-now + 1] == s:
				now -= 1
			else:
				ok = False
				break
		elif len(q1) > 1 and q1[1] == s:
			now = 1
		elif len(q2) > 1 and q2[1] == s:
			now -= 1
		else:
			ok = False
			break
	if not ok:
		print('NO')
	else:
		print('YES')
		for s in Alp:
			if not defined[ord(s) - 97]:
				q1.append(s)
		print(''.join(q2[::-1] + q1[1:]))


t = int(input())
arrs = ['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']
letts = {}
for p in range(t):
	for a in arrs:
		letts[a] = 1
	s = str(input().strip())
	s1 = []
	json = {}
	right = {}
	left = {}
	for i in range(len(s)):
		if i == len(s) - 1:
			break
		if s[i] in json:
			json[s[i]][s[i + 1]] = 1
		else:
			json[s[i]] = {s[i + 1]: 1}
	is_poss = True
	for le in json:
		if not is_poss:
			break
		if len(json[le].keys()) > 2:
			is_poss = False
			break
		else:
			for pe in json[le]:
				rval = right.get(pe)
				lval = left.get(pe)
				check_r = right.get(le)
				check_l = left.get(le)
				if rval == le or lval == le:
					continue
				elif rval != None and lval != None:
					is_poss = False
					break
				elif rval == None and check_l == None:
					right[pe] = le
					left[le] = pe
				elif lval == None and check_r == None:
					left[pe] = le
					right[le] = pe
				else:
					is_poss = False
					break
	final = ''
	curr = ''
	if not is_poss:
		print('NO')
		continue
	else:
		for r in right:
			if not r in left:
				final = r
				curr = final
				letts[curr] = 0
				break
	if len(s) == 1:
		final = s
		letts[final] = 0
	if final == '':
		print('NO')
		continue
	else:
		for j in range(len(right.keys())):
			final += right[curr]
			curr = right[curr]
			letts[curr] = 0
		for l in letts:
			if letts[l] == 1:
				final += l
		print('YES')
		print(final)


from sys import stdin, stdout
T = int(stdin.readline())
for i in range(T):
	s = stdin.readline().strip()
	kb = s[0]
	pos = 0
	chars = [True] * (ord('z') + 1 - ord('a'))
	chars[ord(kb) - ord('a')] = False
	for (i, ch) in enumerate(s[1:]):
		chars[ord(ch) - ord('a')] = False
		if len(kb) == 1:
			kb = ch + kb
		else:
			idx = kb.find(ch)
			if idx == -1:
				if pos == 0:
					kb = ch + kb
				elif pos == len(kb) - 1:
					kb = kb + ch
					pos = len(kb) - 1
				else:
					stdout.write('NO\n')
					break
			elif pos == 0 and idx == 1 or (pos == len(kb) - 1 and idx == len(kb) - 2) or idx == pos - 1 or (idx == pos + 1):
				pos = idx
			else:
				stdout.write('NO\n')
				break
	else:
		stdout.write('YES\n')
		for i in range(ord('z') + 1 - ord('a')):
			if chars[i] == True:
				kb += chr(i + ord('a'))
		stdout.write(kb + '\n')


def get_adjecent_char(password, find_char):
	res = [i for i in range(len(password)) if password.startswith(find_char, i)]
	pos = [(i - 1, i + 1) for i in res]
	final = set()
	for (i, j) in pos:
		if 0 <= i < len(password):
			final.add(password[i])
		if 0 <= j < len(password):
			final.add(password[j])
	return [i for i in final]
for i in range(int(input())):
	s = input()
	default_keyboard = 'abcdefghijklmnopqrstuvwxyz'
	impossible = False
	s_list = set([char for char in s])
	s_dict = {}
	extreme_counter = 0
	extremes = []
	for i in s_list:
		chars = get_adjecent_char(s, i)
		if len(chars) > 2:
			impossible = True
			break
		if len(chars) == 1:
			extreme_counter += 1
			extremes.append(i)
		s_dict[i] = chars
	if extreme_counter != 2 and len(s) > 1:
		impossible = True
	if impossible:
		print('NO')
		continue
	if len(s) == 1:
		default_keyboard = default_keyboard.replace(s, '')
		print('YES')
		print(s + default_keyboard)
		continue
	current_string = extremes[0] + s_dict[extremes[0]][0]
	b_previous = current_string[-2]
	previous = current_string[-1]
	while previous != extremes[1]:
		(i, j) = s_dict[previous]
		p = i if i != b_previous else j
		current_string += p
		b_previous = current_string[-2]
		previous = current_string[-1]
	for i in current_string:
		default_keyboard = default_keyboard.replace(i, '')
	personalized_keyboard = current_string + default_keyboard
	print('YES')
	print(personalized_keyboard)


kl = int(input())
for l in range(kl):
	s = str(input())
	d = {}
	b = set()
	b1 = set()
	b1s = []
	b2 = set()
	al = 'abcdefghijklmnopqrstuvwxyz'
	pr = 1
	if len(s) == 1:
		k = al.find(s)
		rz = s
		al = al[:k] + al[k + 1:]
	else:
		s = s[1] + s + s[len(s) - 2]
		for i in range(1, len(s) - 1):
			d[s[i]] = set()
		for i in range(1, len(s) - 1):
			d[s[i]].add(s[i - 1])
			d[s[i]].add(s[i + 1])
			b.add(s[i])
			if len(d[s[i]]) > 2:
				pr = 0
				break
			elif len(d[s[i]]) == 1:
				b1.add(s[i])
			elif len(d[s[i]]) == 2:
				b2.add(s[i])
				if s[i] in b1:
					b1.remove(s[i])
		for tk in b1:
			b1s += tk
		if len(b1) != 2:
			pr = 0
		if pr:
			rz = b1s[0]
			k = al.find(rz)
			al = al[:k] + al[k + 1:]
			for i in range(1, len(b2) + 1):
				for bk in d[rz[i - 1]]:
					rz += bk
					k = al.find(bk)
					al = al[:k] + al[k + 1:]
				d[rz[i]].remove(rz[i - 1])
			rz += b1s[1]
			k = al.find(b1s[1])
			al = al[:k] + al[k + 1:]
	if pr:
		print('YES')
		print(rz + al)
	else:
		print('NO')


from math import *
import sys
sys.setrecursionlimit(10 ** 9)
ff = 0

def dfs(x, vis, par, ans, ch, st, anss):
	global ff
	if vis[x] == 0:
		vis[x] = 1
		if ch == 0:
			anss.append(chr(x + ord('a')))
		else:
			anss.insert(0, chr(x + ord('a')))
		for i in ans[x]:
			if i == par:
				continue
			dfs(i, vis, x, ans, ch, st, anss)
			if x == st:
				ch = 1
	else:
		ff = 1
t = int(input())
for y in range(t):
	ff = 0
	s = input()
	n = len(s)
	ans = [[] for i in range(26)]
	vis = [0 for i in range(26)]
	flag = 1
	for i in range(1, n):
		ind = ord(s[i]) - ord('a')
		ind1 = ord(s[i - 1]) - ord('a')
		if ind1 not in ans[ind]:
			ans[ind].append(ind1)
			ans[ind1].append(ind)
			if len(ans[ind]) > 2 or len(ans[ind1]) > 2:
				flag = 0
				break
	if flag == 0:
		print('NO')
	else:
		ansss = []
		for i in range(26):
			if vis[i] == 0:
				anss = []
				dfs(i, vis, -1, ans, 0, i, anss)
				ansss.extend(anss)
		if ff == 0:
			print('YES')
			print(''.join(ansss))
		else:
			print('NO')


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for tests in range(t):
	s = input().strip()
	if len(s) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	L = [set() for i in range(26)]
	for i in range(1, len(s)):
		x = ord(s[i]) - 97
		y = ord(s[i - 1]) - 97
		L[x].add(y)
		L[y].add(x)
	LL = [len(l) for l in L]
	C = Counter(LL)
	if max(LL) > 2 or C[1] != 2:
		print('NO')
		continue
	NOW = LL.index(1)
	USE = [0] * 26
	USE[NOW] = 1
	ANS = chr(NOW + 97)
	NOW = list(L[NOW])[0]
	USE[NOW] = 1
	ANS += chr(NOW + 97)
	while LL[NOW] == 2:
		for x in L[NOW]:
			if USE[x] == 0:
				NOW = x
				USE[x] = 1
				ANS += chr(x + 97)
	for i in range(26):
		if USE[i] == 0:
			ANS += chr(i + 97)
	print('YES')
	print(ANS)


T = int(input())
for _ in range(T):
	s = input()
	x = [''] * 100
	p = 50
	x[p] = s[0]
	vis = {s[0]}
	flag = True
	for i in s[1:]:
		if x[p - 1] == i:
			p -= 1
		elif x[p + 1] == i:
			p += 1
		elif not x[p + 1]:
			x[p + 1] = i
			if i in vis:
				flag = False
			else:
				vis.add(i)
			p += 1
		elif not x[p - 1]:
			x[p - 1] = i
			if i in vis:
				flag = False
			else:
				vis.add(i)
			p -= 1
		else:
			flag = False
	res = ''.join(x)
	res += ''.join(filter(lambda j: j not in x, [chr(ord('a') + i) for i in range(26)]))
	print('YES\n%s' % res if flag else 'NO')


import string
for _ in range(int(input())):
	a = list(map(str, input()))
	a1 = set(string.ascii_lowercase)
	ptr = 1
	flag = 0
	ans = [-1, a[0], -1]
	st = {a[0]}
	for i in range(1, len(a)):
		if a[i] not in st:
			if ans[ptr + 1] == -1:
				ans[ptr + 1] = a[i]
				ptr += 1
				ans.append(-1)
				st.add(a[i])
			elif ans[ptr - 1] == -1:
				ans[ptr - 1] = a[i]
				ptr -= 1
				ans.insert(0, -1)
				if ptr == 0:
					ptr = 1
				st.add(a[i])
			else:
				flag = 1
				break
		elif a[i] in st:
			if ans[ptr + 1] == a[i]:
				ptr += 1
			elif ans[ptr - 1] == a[i]:
				ptr -= 1
			else:
				flag = 1
				break
	if flag == 1:
		print('NO')
	else:
		trueans = []
		for i in st:
			a1.remove(i)
		for i in range(1, len(ans) - 1):
			trueans.append(ans[i])
		for i in a1:
			trueans.append(i)
		print('YES')
		print(''.join(map(str, trueans)))


num_t = int(input())
for _ in range(num_t):
	s = input()
	d1 = {}
	d2 = {}
	p = s[0]
	failed = False
	alpha = p
	for c in s[1:]:
		if p in d1 and d1[p] == c or (p in d2 and d2[p] == c):
			p = c
			continue
		if p not in d1 and c not in alpha:
			d1[p] = c
			d2[c] = p
			alpha = alpha + c
		elif p not in d2 and c not in alpha:
			d2[p] = c
			d1[c] = p
			alpha = c + alpha
		else:
			failed = True
			break
		p = c
	if failed:
		print('NO')
	else:
		print('YES')
		import string
		print(alpha + ''.join(map(str, (c for c in string.ascii_lowercase if c not in alpha))))


az = set('abcdefghijklmnopqrstuvwxyz')
for _ in range(int(input())):
	s = input()
	s = s[0] + s + s[-1]
	g = {}
	n = len(s)
	for i in range(1, n - 1):
		if s[i] not in g:
			g[s[i]] = set()
		g[s[i]].update(s[i - 1:i + 2])
		g[s[i]].discard(s[i])
	if any(map(lambda x: len(x) > 2, g.values())) or all(map(lambda x: len(x) == 2, g.values())):
		print('NO')
	else:
		for (root, v) in g.items():
			if len(v) == 1:
				break
		r = root
		while len(r) < len(g):
			for n in g[root]:
				if n not in r:
					r += n
					root = n
					break
		print('YES')
		print(r + ''.join(az.difference(r)))


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		S = input().strip()
		ans = [float('inf')] * 26
		for (s, n) in zip(S, S[1:]):
			if ans[ord(s) - ord('a')] == float('inf'):
				ans[ord(s) - ord('a')] = 0
			if ans[ord(n) - ord('a')] != float('inf'):
				if abs(ans[ord(s) - ord('a')] - ans[ord(n) - ord('a')]) >= 2:
					print('NO')
					break
			elif not ans[ord(s) - ord('a')] + 1 in ans:
				ans[ord(n) - ord('a')] = ans[ord(s) - ord('a')] + 1
			elif not ans[ord(s) - ord('a')] - 1 in ans:
				ans[ord(n) - ord('a')] = ans[ord(s) - ord('a')] - 1
			else:
				print('NO')
				break
		else:
			print('YES')
			ans2 = []
			for (i, a) in enumerate(ans):
				ans2.append([a, i])
			ans2.sort()
			for a in ans2:
				print(chr(a[1] + ord('a')), end='')
			print('')
main()


from sys import stdin, stdout
import math, collections
mod = 10 ** 9 + 7
str = 'qwertyuiopasdfghjklzxcvbnm'
for _ in range(int(input())):
	s = input()
	ans = True
	sol = s[:2]
	temp = -1
	for i in range(2, len(s)):
		if s[i] in sol:
			if temp == -1:
				if s[i] == sol[-2]:
					temp = -2
				else:
					ans = False
					break
			elif temp == -len(sol):
				if s[i] == sol[-len(sol) + 1]:
					temp = -(len(sol) - 1)
				else:
					ans = False
					break
			elif s[i] == sol[temp - 1]:
				temp -= 1
			elif s[i] == sol[temp + 1]:
				temp += 1
			else:
				ans = False
				break
		elif temp == -1:
			sol += s[i]
		elif temp == -len(sol):
			sol = s[i] + sol
			temp = -len(sol)
		else:
			ans = False
			break
	if ans:
		print('YES')
		for i in range(26):
			if str[i] not in sol:
				sol += str[i]
		print(sol)
	else:
		print('NO')


from collections import defaultdict
t = int(input())
q = ['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']
for _ in range(t):
	s = input()
	d = defaultdict(set)
	st = []
	tf = True
	for i in range(len(s)):
		if not st:
			st.append(s[i])
			d[s[i]] = set()
		elif s[i] not in d:
			if st[-1] == s[i - 1]:
				st.append(s[i])
				d[s[i]].add(s[i - 1])
				d[s[i - 1]].add(s[i])
			elif st[0] == s[i - 1]:
				st.insert(0, s[i])
				d[s[i]].add(s[i - 1])
				d[s[i - 1]].add(s[i])
			else:
				tf = False
				break
		elif s[i - 1] not in d[s[i]]:
			tf = False
			break
	if tf:
		print('YES')
		print(''.join(st), end='')
		for i in q:
			if i not in d:
				print(i, end='')
		print()
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	res = ''
	st = set()
	fl = True
	pos = 0
	for x in s:
		if res == '':
			res = res + x
			pos = 0
			st.add(x)
		elif x in st:
			if pos - 1 > -1:
				if res[pos - 1] == x:
					pos -= 1
					fl = True
					continue
				else:
					fl = False
			if pos + 1 < len(res):
				if res[pos + 1] == x:
					pos += 1
					fl = True
					continue
				else:
					fl = False
			if fl == False:
				break
		elif pos == 0:
			pos = 0
			res = x + res
			st.add(x)
		elif pos == len(res) - 1:
			pos += 1
			res = res + x
			st.add(x)
		else:
			fl = False
			break
	if not fl:
		print('NO')
	else:
		print('YES')
		for i in range(97, 123):
			if chr(i) not in st:
				res = res + chr(i)
		print(res)


import string
import sys
input = sys.stdin.readline
low = string.ascii_lowercase
t = int(input())
for _ in range(t):
	arr = list(map(str, input().strip()))
	n = len(arr)
	if len(arr) <= 2:
		print('YES')
		print(''.join(arr), end='')
		for i in low:
			if i not in arr:
				print(i, end='')
		print()
	else:
		near = dict()
		for i in range(n):
			near[arr[i]] = dict()
		for i in range(1, n):
			near[arr[i]][arr[i - 1]] = 1
			near[arr[i - 1]][arr[i]] = 1
		ones = 0
		twos = 0
		flag = 0
		l1 = []
		l2 = []
		for i in near:
			if len(near[i]) == 1:
				ones += 1
				l1 += [i]
			elif len(near[i]) == 2:
				twos += 1
				l2 += [i]
			else:
				flag = 1
		if ones != 2 or flag == 1:
			print('NO')
		else:
			print('YES')
			start = l1[0]
			ans = [l1[0]]
			vis = dict()
			vis[l1[0]] = 1
			flag2 = 1
			while flag2 == 1:
				flag2 = 0
				for i in near[ans[-1]]:
					if i not in vis:
						ans += [i]
						vis[i] = 1
						flag2 = 1
						break
			print(''.join(ans), end='')
			for i in low:
				if i not in ans:
					print(i, end='')
			print()


T = int(input())
alph = 'abcdefghijklkmnopqrstuvwxyz'

def tc():
	s = input().strip()
	kseq = ''
	idx = 0
	for l in s:
		if l not in kseq:
			if idx > 0 and idx < len(kseq) - 1:
				print('NO')
				return
			elif idx == 0:
				kseq = l + kseq
			elif idx == len(kseq) - 1:
				kseq += l
				idx = len(kseq) - 1
			else:
				print('O NO')
		elif idx > 0 and idx < len(kseq) - 1:
			if l == kseq[idx - 1]:
				idx -= 1
			elif l == kseq[idx + 1]:
				idx += 1
			else:
				print('NO')
				return
		elif idx == 0:
			if l == kseq[1]:
				idx = 1
			else:
				print('NO')
				return
		elif idx == len(kseq) - 1:
			if l == kseq[idx - 1]:
				idx -= 1
			else:
				print('NO')
				return
	for a in alph:
		if a not in kseq:
			kseq += a
	print('YES')
	print(kseq)
for _ in range(T):
	tc()


for i in range(int(input())):
	letters = ['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']
	s = input()
	keyboard = [None, s[0], None]
	j = 1
	x = 0
	for i in range(1, len(s)):
		if keyboard[j + 1] == s[i]:
			j = j + 1
			continue
		elif keyboard[j - 1] == s[i]:
			j = j - 1
			continue
		elif s[i] not in keyboard:
			if keyboard[j + 1] == None:
				keyboard.insert(-1, s[i])
				j = len(keyboard) - 2
			elif keyboard[j - 1] == None:
				keyboard.insert(1, s[i])
				j = 1
			else:
				x = 1
				break
		else:
			x = 1
			break
	if x == 0:
		keyboard.pop()
		keyboard.pop(0)
		for i in letters:
			if i not in set(s):
				keyboard.append(i)
		print('YES')
		print(''.join(keyboard))
	else:
		print('NO')


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))
alph = 'bacdefghijklmnopqrstuvwxyz'
dic = {}
for i in alph:
	dic[i] = False

def solve():
	s = input()
	t = {}
	idx = 30
	local_dic = dic.copy()
	mx = 0
	mn = math.inf
	for b in s:
		if idx - 1 in t and t[idx - 1] == b:
			idx -= 1
			continue
		if idx + 1 in t and t[idx + 1] == b:
			idx += 1
			continue
		if not idx - 1 in t and (not local_dic[b]):
			t[idx - 1] = b
			local_dic[b] = True
			idx -= 1
			continue
		if not idx + 1 in t and (not local_dic[b]):
			t[idx + 1] = b
			local_dic[b] = True
			idx += 1
			continue
		print('NO')
		return
	result = ''
	for i in sorted(t.keys()):
		result += t[i]
	for (k, v) in local_dic.items():
		if not v:
			result += k
	print('YES')
	print(result)
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


from collections import deque
w = ['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']
for _ in range(int(input())):
	s = input()
	o = []
	l = deque(o)
	k = set()
	z = s[0]
	k.add(z)
	l.append(z)
	s = s[1:]
	j = 0
	f = 0
	for i in s:
		if i not in k:
			if j == len(l) - 1:
				l.append(i)
				j = j + 1
				k.add(i)
				continue
			if j == 0:
				l.appendleft(i)
				k.add(i)
				continue
			f = 1
			break
		if j - 1 > -1:
			if l[j - 1] == i:
				j = j - 1
				continue
		if j + 1 < len(l):
			if l[j + 1] == i:
				j = j + 1
				continue
		f = 1
		break
	if f == 1:
		print('NO')
	else:
		for i in w:
			if i in k:
				continue
			l.append(i)
		e = ''
		for i in l:
			e = e + i
		print('YES')
		print(e)


t = int(input())
for _ in range(t):
	S = input()
	used = [0] * 26
	ans = [0] * 26 + [S[0]] + [0] * 26
	y_n = 'YES'
	used[ord(S[0]) - 97] = 1
	i = 26
	for s in S[1:]:
		if used[ord(s) - 97] == 1:
			if ans[i + 1] == s:
				i += 1
			elif ans[i - 1] == s:
				i -= 1
			else:
				y_n = 'NO'
				break
		elif ans[i + 1] == 0:
			ans[i + 1] = s
			i += 1
			used[ord(s) - 97] = 1
		elif ans[i - 1] == 0:
			ans[i - 1] = s
			i -= 1
			used[ord(s) - 97] = 1
		else:
			y_n = 'NO'
			break
	if y_n == 'NO':
		print(y_n)
	else:
		print(y_n)
		ans_ = ''
		for a in ans:
			if a != 0:
				ans_ += a
		for k in range(26):
			if used[k] == 0:
				ans_ += chr(k + 97)
		print(ans_)


t = int(input())

def dfs_visit(G, u, found_cycle, pred_node, marked):
	if found_cycle[0]:
		return
	marked[u] = True
	for v in G[u]:
		if marked[v] and v != pred_node:
			found_cycle[0] = True
			return
		if not marked[v]:
			dfs_visit(G, v, found_cycle, u, marked)

def cycle_exists(G):
	marked = {u: False for u in G}
	found_cycle = [False]
	for u in G:
		if not marked[u]:
			dfs_visit(G, u, found_cycle, u, marked)
		if found_cycle[0]:
			break
	return found_cycle[0]

def dfs_util(x, marked):
	global adj
	marked[x] = True
	dfs_said.append(chr(x + 97))
	for i in adj[x]:
		if marked[i] == False:
			dfs_util(i, marked)

def dfs(x):
	global adj
	marked = [False] * 26
	dfs_util(x, marked)
	return dfs_said
for i in range(t):
	s = input()
	if len(s) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	s = '-' + s + '-'
	adj = {}
	flag = 0
	for j in range(1, len(s) - 1):
		if ord(s[j]) - 97 not in adj:
			adj[ord(s[j]) - 97] = []
		c1 = s[j - 1]
		c2 = s[j + 1]
		if c1 != '-':
			if ord(c1) - 97 not in adj[ord(s[j]) - 97]:
				if len(adj[ord(s[j]) - 97]) < 2:
					adj[ord(s[j]) - 97].append(ord(c1) - 97)
				else:
					flag = 1
					break
		if c2 != '-':
			if ord(c2) - 97 not in adj[ord(s[j]) - 97]:
				if len(adj[ord(s[j]) - 97]) < 2:
					adj[ord(s[j]) - 97].append(ord(c2) - 97)
				else:
					flag = 1
					break
	if flag == 1:
		print('NO')
		continue
	if cycle_exists(adj):
		print('NO')
		continue
	else:
		for j in adj:
			if len(adj[j]) == 1:
				start = j
				break
	dfs_said = []
	path = dfs(start)
	done = [1] * 26
	for j in range(len(path)):
		done[ord(path[j]) - 97] = 0
	path2 = ''
	for j in range(len(done)):
		path2 = path2 + done[j] * chr(j + 97)
	print('YES')
	print(''.join(path) + path2)


import sys
input = sys.stdin.readline
t = int(input())
orda = ord('a')
for _ in range(t):
	s = input().rstrip()
	if len(s) == 1:
		ans = ''.join([chr(item + orda) for item in range(26)])
		print('YES')
		print(ans)
		continue
	edge = [set() for _ in range(26)]
	for (c1, c2) in zip(s, s[1:]):
		frm = ord(c1) - orda
		too = ord(c2) - orda
		edge[frm].add(too)
		edge[too].add(frm)
	ones = []
	visited = [False] * 26
	ok = True
	for (i, e) in enumerate(edge):
		if len(e) > 2:
			ok = False
		elif len(e) == 1:
			ones.append(i)
	if not ok:
		print('NO')
		continue
	if len(ones) < 2:
		print('NO')
		continue
	ans = []
	for v in ones:
		if visited[v]:
			continue
		st = []
		st.append((v, -1))
		while st:
			(v, pv) = st.pop()
			if visited[v]:
				ok = False
				break
			visited[v] = True
			ans.append(v)
			for nv in edge[v]:
				if nv == pv:
					continue
				st.append((nv, v))
	seen = set(ans)
	for i in range(26):
		if i not in seen:
			ans.append(i)
	print('YES')
	print(''.join([chr(item + orda) for item in ans]))


from collections import defaultdict
T = int(input())
for _ in range(T):
	s = input()
	if len(s) == 1:
		ans = [s]
		for alpha_i in 'abcdefghijklmnopqrstuvwxyz':
			if alpha_i != s:
				ans.append(alpha_i)
		print('YES')
		print(''.join(ans))
		continue
	adj_list = defaultdict(set)
	for i in range(len(s) - 1):
		adj_list[s[i]].add(s[i + 1])
		adj_list[s[i + 1]].add(s[i])
	sta = ''
	flag = False
	for k in adj_list.keys():
		if len(adj_list[k]) >= 3:
			flag = True
		elif len(adj_list[k]) == 1:
			sta = k
	if sta == '' or flag:
		print('NO')
		continue
	ans = [sta]
	cur = sta
	pre = ''
	for i in range(len(s) - 1):
		for nex in adj_list[cur]:
			if nex != pre:
				ans.append(nex)
				pre = cur
				cur = nex
				break
	s = set(ans)
	for alpha_i in 'abcdefghijklmnopqrstuvwxyz':
		if alpha_i not in s:
			ans.append(alpha_i)
	print('YES')
	print(''.join(ans))


alpha = [chr(i) for i in range(97, 123)]

def is_adj(n, x, y, s):
	st1 = n[x] + n[y]
	st2 = n[y] + n[x]
	if st1 in s or st2 in s:
		return True
	return False
test = int(input())
for t in range(test):
	n = str(input())
	s = n[0]
	dalpha = {}
	dalpha[n[0]] = True
	ready = True
	for x in range(1, len(n)):
		if n[x] in s:
			if is_adj(n, x, x - 1, s):
				continue
			else:
				ready = False
				break
		elif s.startswith(n[x - 1]):
			s = n[x] + s
			dalpha[n[x]] = True
		elif s.endswith(n[x - 1]):
			s = s + n[x]
			dalpha[n[x]] = True
		else:
			ready = False
			break
	if ready:
		final = s
		for a in alpha:
			if dalpha.get(a, False):
				continue
			final += a
		print('YES')
		print(final)
	else:
		print('NO')


t = int(input())
ans_list = []
for i in range(t):
	able = True
	ans = []
	s = list(input())
	now = 0
	for g in range(len(s)):
		if not s[g] in ans and now == len(ans) - 1:
			ans.append(s[g])
			now = len(ans) - 1
		elif not s[g] in ans and now == 0:
			ans.insert(0, s[g])
			now = 0
		elif ans[max(now - 1, 0)] == s[g]:
			now -= 1
		elif ans[min(now + 1, len(ans) - 1)] == s[g]:
			now += 1
		else:
			able = False
			break
	if able:
		a = [chr(i) for i in range(97, 97 + 26)]
		str_ans = ''
		for l in range(len(a)):
			if not a[l] in ans:
				ans += a[l]
		for m in range(len(ans)):
			str_ans += ans[m]
		ans_list.append(['YES', str_ans])
	else:
		ans_list.append(['NO', ''])
for n in range(t):
	if ans_list[n][0] == 'YES':
		print('YES')
		print(ans_list[n][1])
	else:
		print('NO')


t = int(input())
for t_ in range(t):
	s = input()
	keys = 'abcdefghijklmnopqrstuvwxyz'
	k = ''
	for x in s:
		ok = False
		if k == '':
			k += x
			i = 0
			ok = True
		elif x not in k:
			if i == 0:
				k = x + k
				i = 0
				ok = True
			elif i == len(k) - 1:
				k = k + x
				i += 1
				ok = True
		else:
			if i > 0:
				if k[i - 1] == x:
					i -= 1
					ok = True
			if i < len(k) - 1:
				if k[i + 1] == x:
					i += 1
					ok = True
		if ok == False:
			print('NO')
			break
	if ok == True:
		for x in keys:
			if x not in k:
				k += x
		print('YES')
		print(k)


alph = 'qwertyuiopasdfghjklzxcvbnm'
for _ in range(int(input())):
	s = input()
	ans = s[0]
	t = 0
	for i in range(1, len(s)):
		if s[i] not in ans:
			if s[i - 1] == ans[-1]:
				ans += s[i]
			elif s[i - 1] == ans[0]:
				ans = s[i] + ans
			else:
				t = 1
				break
		elif abs(ans.find(s[i]) - ans.find(s[i - 1])) > 1:
			t = 1
			break
	if t:
		print('NO')
	else:
		print('YES')
		print(ans + ''.join([i for i in alph if i not in ans]))


m = int(input())
for i in range(m):
	s = input()
	index = 0
	flag = 0
	l = ''
	for j in range(len(s)):
		if not s[j] in l:
			if len(l) - 1 == index:
				l += s[j]
				index = len(l) - 1
			elif index == 0:
				l = s[j] + l
			else:
				flag = 1
				break
		elif index - 1 >= 0 and l[index - 1] == s[j]:
			index -= 1
		elif index + 1 < len(l) and l[index + 1] == s[j]:
			index += 1
		else:
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')
		for j in range(ord('a'), ord('z') + 1):
			if not chr(j) in l:
				l += chr(j)
		print(l)


def bfs(d, visited, v):
	queue = []
	queue.append(v)
	ans = []
	while queue:
		s = queue.pop(0)
		if visited[s] == False:
			visited[s] = True
			ans.append(s)
			for i in d[s]:
				queue.append(i)
	return ans
alpha = []
for i in range(26):
	alpha.append(chr(ord('a') + i))
for t in range(int(input())):
	s = input()
	s1 = set(s)
	if len(s) == 1:
		print('YES')
		index = ord(s[0]) - ord('a')
		temp = alpha[index]
		alpha[index] = alpha[0]
		alpha[0] = temp
		print(''.join(alpha))
	else:
		d = {}
		d1 = {}
		for i in s1:
			d[i] = []
			d1[i] = 0
		for i in range(len(s) - 1):
			d[s[i]].append(s[i + 1])
			d[s[i + 1]].append(s[i])
		for i in s1:
			d[i] = list(set(d[i]))
			d1[i] = len(d[i])
		c = 0
		flag = 0
		for i in s1:
			if d1[i] == 1:
				c += 1
			elif d1[i] > 2:
				flag = 1
				break
		if flag == 1 or c != 2:
			print('NO')
		else:
			print('YES')
			for i in s1:
				if d1[i] == 1:
					deg = i
					break
			visited = {}
			for i in s1:
				visited[i] = False
			ans = bfs(d, visited, deg)
			rem = set(alpha).difference(set(ans))
			print(''.join(ans) + ''.join(list(rem)))


mark1 = {}
for i in range(97, 123):
	mark1[chr(i)] = 0
for _ in range(int(input())):
	S = input()
	j = -1
	mark = mark1.copy()
	flag = 0
	stri = ''
	for i in S:
		if len(stri) < 2:
			if mark.get(i, -1) == 0:
				stri += i
				mark[i] = 1
				j += 1
				continue
		if stri[j] == i:
			continue
		if j == 0:
			if stri[j + 1] == i:
				j += 1
				continue
			if mark.get(i, -1) == 0:
				stri = i + stri
				mark[i] = 1
				j = 0
			else:
				flag = 1
				break
		elif j == len(stri) - 1:
			if stri[j - 1] == i:
				j -= 1
				continue
			if mark.get(i, -1) == 0:
				stri = stri + i
				mark[i] = 1
				j = len(stri) - 1
			else:
				flag = 1
				break
		else:
			if stri[j - 1] == i:
				j -= 1
				continue
			if stri[j + 1] == i:
				j += 1
				continue
			else:
				flag = 1
				break
	if flag == 1:
		print('NO')
	else:
		print('YES')
		for (i, j) in mark.items():
			if j == 0:
				stri += i
		print(stri)


n = int(input())
pykk = 0
for irerre in range(n):
	latin = list('qwertyuioplkjhgfdsazxcvbnm')
	s = input()
	if len(s) == 1:
		tabl = [s[0]]
		dasie = True
	else:
		tabl = [-1] * 60
		dasie = True
		tabl[30] = s[0]
		tabl[31] = s[1]
		ind = 31
		i = 1
		dik = {}
		for li in latin:
			dik[li] = set()
		dik[s[0]].add(30)
		dik[s[1]].add(31)
		while True:
			if ind < 2 or ind > 57:
				dasie = False
				break
			i += 1
			if i >= len(s):
				break
			if tabl[ind - 1] == s[i]:
				ind -= 1
			elif tabl[ind + 1] == s[i]:
				ind += 1
			else:
				dupa = 0
				if tabl[ind + 1] == -1 or tabl[ind + 1] == s[i]:
					ind += 1
					tabl[ind] = s[i]
					dik[s[i]].add(ind)
					if len(dik[s[i]]) >= 2:
						dasie = False
						break
				elif tabl[ind - 1] == -1 or tabl[ind - 1] == s[i]:
					ind -= 1
					tabl[ind] = s[i]
					dik[s[i]].add(ind)
					if len(dik[s[i]]) >= 2:
						dasie = False
						break
				else:
					dasie = False
					break
	if not dasie:
		print('NO')
	else:
		print('YES')
		slow = []
		for i in tabl:
			if i != -1:
				slow.append(i)
		for j in latin:
			if j not in slow:
				slow.append(j)
		print(''.join(slow))


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)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 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
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	s = S()
	if len(s) == 1:
		print('YES')
		print(*[chr(i + 97) for i in range(26)], sep='')
		continue
	a = [set() for i in range(26)]
	for i in range(1, len(s)):
		x = ord(s[i]) - 97
		y = ord(s[i - 1]) - 97
		a[x].add(y)
		a[y].add(x)
	p = sorted([len(i) for i in a if i])
	if p[-1] > 2 or (len(p) > 1 and p[1] > 1):
		print('NO')
	else:
		m = []
		v = [1] * 26
		for i in range(26):
			if len(a[i]) == 1:
				stk = [i]
				m = [chr(i + 97)]
				v[i] = 0
				break
		while stk:
			p = stk.pop()
			for i in a[p]:
				if v[i]:
					stk += (i,)
					m += (chr(i + 97),)
					v[i] = 0
		for el in [chr(i + 97) for i in range(26)]:
			if el not in m:
				m += (el,)
		print('YES')
		print(*m, sep='')


t = int(input())

def get(s):
	return ord(s) - ord('a')

def solve():
	s = input().strip()
	vis = [False] * 26
	a = [0] * 54
	j = 27
	a[j] = s[0]
	vis[get(s[0])] = True
	for i in range(1, len(s)):
		if vis[get(s[i])]:
			if a[j - 1] == s[i]:
				j -= 1
			elif a[j + 1] == s[i]:
				j += 1
			else:
				print('NO')
				return
		else:
			if not a[j - 1]:
				j -= 1
			elif not a[j + 1]:
				j += 1
			else:
				print('NO')
				return
			a[j] = s[i]
			vis[get(s[i])] = 1
	k = 0
	while a[k] == 0:
		k += 1
	for i in range(26):
		if not vis[i]:
			k -= 1
			a[k] = chr(i + ord('a'))
	print('YES')
	for i in range(26):
		print(a[i + k], end='')
	print()
while t:
	t -= 1
	solve()


from collections import deque

def append_char(ch, a, left, b):
	if not ch in b:
		return False
	if left:
		a.appendleft(ch)
	else:
		a.append(ch)
	b.remove(ch)
	return True
t = int(input())
for _ in range(t):
	s = input()
	a = deque()
	possible = True
	b = set()
	for i in range(26):
		b.add(chr(ord('a') + i))
	append_char(s[0], a, False, b)
	if len(s) > 1:
		append_char(s[1], a, False, b)
	if len(s) > 2:
		pos = 1
		for i in range(2, len(s)):
			s_i = s[i]
			if pos == 0:
				if a[1] == s_i:
					pos = 1
				elif not append_char(s_i, a, True, b):
					possible = False
					break
			elif pos == len(a) - 1:
				if a[-2] == s_i:
					pos -= 1
				else:
					if not append_char(s_i, a, False, b):
						possible = False
						break
					pos += 1
			elif a[pos - 1] == s_i:
				pos -= 1
			elif a[pos + 1] == s_i:
				pos += 1
			else:
				possible = False
				break
	if possible:
		print('YES')
		print(''.join(a) + ''.join(sorted(b)))
	else:
		print('NO')


import string
import sys
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		s = input().strip()
		if len(s) == 1:
			print('YES')
			ret = s
			for c in string.ascii_lowercase:
				if c not in ret:
					ret += c
			print(ret)
			continue
		m = {}
		is_break = False
		for idx in range(len(s)):
			if s[idx] not in m:
				m[s[idx]] = set()
			if idx > 0:
				m[s[idx]].add(s[idx - 1])
			if idx < len(s) - 1:
				m[s[idx]].add(s[idx + 1])
			if len(m[s[idx]]) > 2:
				is_break = True
				break
		if is_break:
			print('NO')
			continue
		key = None
		for (k, v) in m.items():
			if len(v) == 1:
				key = k
		if key is None:
			print('NO')
			continue
		ret = key
		while m[key]:
			next_key = m[key].pop()
			ret += next_key
			m[next_key].remove(key)
			key = next_key
		for c in string.ascii_lowercase:
			if c not in ret:
				ret += c
		print('YES')
		print(ret)
main()


MaxN = 26
L = ord('a')
for T_ in range(int(input())):
	Connect = [[False for i in range(MaxN)] for _ in range(MaxN)]
	ConnectNum = [0 for i in range(MaxN)]
	s = input()
	ans = ''
	if len(s) == 1:
		print('YES')
		for i in range(MaxN):
			ans += chr(i + L)
		print(ans)
		continue
	for i in range(len(s) - 1):
		a = ord(s[i]) - L
		b = ord(s[i + 1]) - L
		if not Connect[a][b]:
			Connect[a][b] = Connect[b][a] = True
			ConnectNum[a] += 1
			ConnectNum[b] += 1
	Node1 = Node2 = NodeNum = 0
	for i in range(MaxN):
		if ConnectNum[i] == 1:
			Node1 += 1
		if ConnectNum[i] == 2:
			Node2 += 1
		if ConnectNum[i] != 0:
			NodeNum += 1
	if Node1 == 2 and Node1 + Node2 == NodeNum:
		print('YES')
		vis = [False for i in range(MaxN)]
		cur = 0
		for cur in range(MaxN):
			if ConnectNum[cur] == 1:
				break
		ans += chr(cur + L)
		vis[cur] = True
		i = 0
		while i < MaxN:
			if not vis[i] and Connect[cur][i]:
				vis[i] = True
				ans += chr(i + L)
				cur = i
				i = 0
			else:
				i += 1
		for i in range(MaxN):
			if not vis[i]:
				ans += chr(i + L)
		print(ans)
		continue
	else:
		print('NO')


import math, collections, sys

def case():
	s = input()
	z = [s[0]]
	atEnd = True
	index = 0
	vis = [0 for i in range(26)]
	vis[ord(s[0]) - 97] = 1
	for i in range(1, len(s)):
		if atEnd:
			if index == 0:
				if vis[ord(s[i]) - 97] and index + 1 < len(z) and (z[index + 1] == s[i]):
					index += 1
				elif not vis[ord(s[i]) - 97]:
					z = [s[i]] + z
					vis[ord(s[i]) - 97] = 1
				else:
					print('NO')
					return
			elif vis[ord(s[i]) - 97] and 0 <= index - 1 and (z[index - 1] == s[i]):
				index -= 1
			elif not vis[ord(s[i]) - 97]:
				z.append(s[i])
				index += 1
				vis[ord(s[i]) - 97] = 1
			else:
				print('NO')
				return
		elif z[index - 1] == s[i]:
			index -= 1
		elif z[index + 1] == s[i]:
			index += 1
		else:
			print('NO')
			return
		if index == 0 or index == len(z) - 1:
			atEnd = True
		else:
			atEnd = False
	for i in 'abcdefghijklmnopqrstuvwxyz':
		if i not in z:
			z.append(i)
	print('YES')
	print(''.join(z))
for _ in range(int(input())):
	case()


t = int(input())
while t != 0:
	s = input()
	ans = s[0]
	f = 0
	for i in range(1, len(s)):
		if s[i] not in ans:
			if s[i - 1] == ans[-1]:
				ans = ans + s[i]
			elif s[i - 1] == ans[0]:
				ans = s[i] + ans
			else:
				f = 1
				break
		else:
			ind1 = ans.find(s[i])
			ind2 = ans.find(s[i - 1])
			if abs(ind1 - ind2) > 1:
				f = 1
				break
	if f == 1:
		print('NO')
	else:
		print('YES')
		print(ans, end='')
		for i in range(26):
			if chr(ord('a') + i) not in ans:
				print(chr(ord('a') + i), end='')
		print()
	t -= 1


def get_char_list_input():
	return list(input())

def get_int_input():
	return int(input())

class ListNode:

	def __init__(self, char, left=None, right=None):
		self.char = char
		self.left = left
		self.right = right

	def is_occupied(self):
		return self.left and self.right

	def has_neighbor(self, node):
		return self.left == node or self.right == node

	def rotate(self):
		(self.left, self.right) = (self.right, self.left)
		if self.left:
			self.left.rotate()
		if self.right:
			self.right.rotate()

	def get_all_linked_char(self, search_left=False, search_right=False):
		linked_lst = [self.char]
		if (self.left == None or not search_left) and (self.right == None or not search_right):
			return linked_lst
		if self.left and search_left:
			linked_lst = self.left.get_all_linked_char(search_left=True) + linked_lst
		if self.right and search_right:
			linked_lst = linked_lst + self.right.get_all_linked_char(search_right=True)
		return linked_lst

	def has_loop(self):
		p = self.right
		while p is not self and p:
			p = p.right
		if p is self:
			return True
		else:
			return False

def check_password(char_list):
	char_dict = {char: ListNode(char) for char in char_list}
	for (char1, char2) in zip(char_list, char_list[1:]):
		(node1, node2) = (char_dict[char1], char_dict[char2])
		if node1.has_neighbor(node2):
			continue
		elif node1.is_occupied() or node2.is_occupied():
			return (False, None)
		elif node1.right == None and node2.left == None:
			node1.right = node2
			node2.left = node1
		elif node1.right == None and node2.right == None:
			node2.rotate()
			node1.right = node2
			node2.left = node1
		elif node1.left == None and node2.right == None:
			node2.right = node1
			node1.left = node2
		else:
			node1.rotate()
			node1.right = node2
			node2.left = node1
	import string
	solution = ''
	s = set(string.ascii_lowercase)
	for char in char_dict:
		if char_dict[char].has_loop():
			return (False, None)
		if char in s:
			linked_lst = char_dict[char].get_all_linked_char(search_left=True, search_right=True)
			solution += ''.join(linked_lst)
			s -= set(linked_lst)
	solution += ''.join(s)
	return (True, solution)

def main():
	n = get_int_input()
	for _ in range(n):
		char_list = get_char_list_input()
		(ok, solution) = check_password(char_list)
		if ok:
			print('YES')
			print(solution)
		else:
			print('NO')
main()


import sys
import math as mt
t = int(input())
for __ in range(t):
	s = input()
	ans = []
	l = [0] * 27
	ch = 1
	l1 = []
	ans.append(s[0])
	l[ord(s[0]) - 97] = 1
	for i in range(1, len(s)):
		if l[ord(s[i]) - 97] == 0:
			if l[ord(s[i - 1]) - 97] == 1:
				if ans[-1] == s[i - 1]:
					ans.append(s[i])
					l[ord(s[i]) - 97] = 1
				elif ans[0] == s[i - 1]:
					ans.insert(0, s[i])
					l[ord(s[i]) - 97] = 1
	for i in range(26):
		if l[i] == 0:
			ans.append(chr(i + 97))
	d = {}
	for i in range(len(ans)):
		d[ans[i]] = i
	for i in range(len(s) - 1):
		if abs(d[s[i]] - d[s[i + 1]]) == 1:
			continue
		ch = 0
	if ch == 0:
		print('NO')
	else:
		print('YES')
		print(*ans, sep='')


from sys import stdin
from string import ascii_lowercase
T = int(stdin.readline())
tests = []
for t in range(T):
	tests.append(stdin.readline())
for test in tests:
	remainedChars = list(ascii_lowercase)
	remainedChars.remove(test[0])
	keysetting = [test[0]]
	head = 0
	impossible = False
	test = test[:-1]
	for i in range(1, len(test)):
		if head == 0:
			if head == len(keysetting) - 1:
				keysetting.append(test[i])
				remainedChars.remove(test[i])
				head += 1
			elif keysetting[head + 1] == test[i]:
				head += 1
			else:
				keysetting.insert(0, test[i])
				try:
					remainedChars.remove(test[i])
				except:
					impossible = True
					break
			continue
		if head == len(keysetting) - 1:
			if keysetting[head - 1] == test[i]:
				head -= 1
			else:
				keysetting.append(test[i])
				head += 1
				try:
					remainedChars.remove(test[i])
				except:
					impossible = True
					break
		elif keysetting[head + 1] == test[i]:
			head += 1
		elif keysetting[head - 1] == test[i]:
			head -= 1
		else:
			impossible = True
			break
	if impossible:
		print('NO')
		continue
	print('YES')
	print(f"{''.join(keysetting) + ''.join(remainedChars)}")


A = set((chr(i) for i in range(97, 123)))
for _ in range(int(input())):
	S = input()
	stri = S[0]
	f = 0
	for i in range(1, len(S)):
		if S[i] not in stri:
			if S[i - 1] == stri[0]:
				stri = S[i] + stri
			elif S[i - 1] == stri[-1]:
				stri = stri + S[i]
			else:
				f = 1
				break
		elif S[i - 1] + S[i] not in stri and S[i] + S[i - 1] not in stri:
			f = 1
			break
	print('NO') if f == 1 else print('YES')
	if f == 0:
		print(stri + ''.join(list(A - set(stri))))


from collections import defaultdict
from string import ascii_lowercase as chars
for _ in range(int(input())):
	s = input().rstrip()
	if len(s) == 1:
		print('YES\n%s' % chars)
		continue
	g = defaultdict(set)
	for i in range(len(s) - 1):
		(c1, c2) = (s[i], s[i + 1])
		if c1 == c2:
			continue
		g[c1].add(c2)
		g[c2].add(c1)
	v = None
	maxSz = 0
	for c in chars:
		sz = len(g[c])
		maxSz = max(maxSz, sz)
		if sz == 1:
			v = c
	if not v or maxSz > 2:
		print('NO')
		continue

	def dfs(v):
		visited.add(v)
		ret.append(v)
		for to in g[v]:
			if to not in visited:
				dfs(to)
	visited = set()
	ret = []
	dfs(v)
	for c in chars:
		if c not in visited:
			visited.add(c)
			ret.append(c)
	print('YES\n%s' % ''.join(ret))


from sys import stdin
from bisect import bisect_left as bl
from bisect import bisect_right as br

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())

class RangedList:

	def __init__(self, start, stop, val=0):
		self.shift = 0 - start
		self.start = start
		self.stop = stop
		self.list = [val] * (stop - start)

	def __setitem__(self, key, value):
		self.list[key + self.shift] = value

	def __getitem__(self, key):
		return self.list[key + self.shift]

	def __repr__(self):
		return str(self.list)

	def __iter__(self):
		return iter(self.list)
alphas = 'abcdefghijklmnopqrstuvwxyz'
t = intput()
for _ in range(t):
	s = input()
	if len(s) == 1:
		print('YES')
		print(alphas)
		continue
	nextto = {}
	for alph in alphas:
		nextto[alph] = set()
	for i in range(len(s)):
		for j in (i - 1, i + 1):
			if j in range(len(s)):
				nextto[s[i]].add(s[j])
	if any((len(x) >= 3 for x in nextto.values())):
		print('NO')
		continue
	if not any((len(x) == 1 for x in nextto.values())):
		print('NO')
		continue
	for x in nextto:
		if len(nextto[x]) == 1:
			start = x
	ans = [start]
	covered = {}
	for x in alphas:
		covered[x] = False
	covered[start] = True
	gotcha = False
	while not all(covered.values()):
		if len(nextto[ans[-1]]) == 0 or (len(nextto[ans[-1]]) == 1 and covered[list(nextto[ans[-1]])[0]]):
			for k in covered:
				if not covered[k] and len(nextto[k]) < 2:
					ans.append(k)
					break
			else:
				print('NO')
				gotcha = True
				break
		else:
			for d in nextto[ans[-1]]:
				if not covered[d]:
					ans.append(d)
		covered[ans[-1]] = True
	if not gotcha:
		print('YES')
		print(''.join(ans))


import sys, math
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	a = insr()
	s = a[0]
	qw = 0
	j = 0
	q = [0] * 26
	q[ord(a[0]) - 97] = 1
	for i in range(1, len(a)):
		if j > 0 and a[i] == s[j - 1]:
			j = j - 1
		elif j + 2 <= len(s) and a[i] == s[j + 1]:
			j = j + 1
		elif j == 0:
			s = a[i] + s
			q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
		elif j == len(s) - 1:
			s = s + a[i]
			j = j + 1
			q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
		else:
			qw = 1
			break
	for i in range(len(q)):
		if q[i] > 1:
			qw = 1
			break
	if qw == 0:
		for i in range(len(q)):
			if q[i] == 0:
				s = s + chr(i + 97)
			if q[i] > 1:
				print('NO')
				break
		print('YES')
		print(s)
	else:
		print('NO')


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

def main():
	for case in range(int(input())):
		no_flag = False
		s = input()
		n = len(s)
		neighbhours = {}
		for i in range(n):
			if s[i] not in neighbhours:
				neighbhours[s[i]] = set()
			if i > 0:
				neighbhours[s[i]].add(s[i - 1])
			if i < n - 1:
				neighbhours[s[i]].add(s[i + 1])
		visited = set()
		answer = []
		if len(s) == 1:
			answer.append(s[0])
			visited.add(s[0])
		else:
			min_n = 99
			max_n = -1
			for key in neighbhours.keys():
				min_n = min(min_n, len(neighbhours[key]))
				max_n = max(max_n, len(neighbhours[key]))
			if min_n > 1 or max_n > 2:
				print('NO')
				continue
			root = ''
			for key in neighbhours.keys():
				if len(neighbhours[key]) == 1:
					root = key
					break
			current = root
			while len(visited) < len(neighbhours):
				answer.append(current)
				visited.add(current)
				for k in neighbhours[current]:
					if k not in visited:
						current = k
		for letter in 'qwertyuioplkjhgfdsazxcvbnm':
			if letter not in visited:
				answer.append(letter)
		print('YES')
		print(''.join(answer))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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()


import sys
from string import ascii_lowercase
r = sys.stdin.readline
for _ in range(int(r())):
	s = r().strip()
	alpa = {key: False for key in ascii_lowercase}
	ans = s[0]
	alpa[s[0]] = True
	flg = True
	for i in range(1, len(s)):
		before_ch = s[i - 1]
		cur_ch = s[i]
		if alpa[cur_ch]:
			idx = ans.index(cur_ch)
			idx2 = ans.index(before_ch)
			if abs(idx2 - idx) != 1:
				print('NO')
				flg = False
				break
		else:
			idx = ans.index(before_ch)
			if idx == 0:
				ans = cur_ch + ans
				alpa[cur_ch] = True
			elif idx == len(ans) - 1:
				ans = ans + cur_ch
				alpa[cur_ch] = True
			else:
				print('NO')
				flg = False
				break
	if flg:
		tmp = [k for (k, v) in alpa.items() if not alpa[k]]
		print('YES')
		print(ans + ''.join(tmp))


import string
t = int(input())
for _ in range(t):
	s = input()
	visited = dict()
	for c in string.ascii_lowercase:
		visited[c] = False
	ans = ['' for _ in range(53)]
	i = 26
	ans[i] = s[0]
	visited[s[0]] = True
	ok = True
	for j in range(1, len(s)):
		c = s[j]
		if visited[c]:
			if ans[i - 1] != c and ans[i + 1] != c:
				ok = False
				break
			elif ans[i - 1] == c:
				i -= 1
			else:
				i += 1
		elif ans[i + 1] == '':
			ans[i + 1] = c
			visited[c] = True
			i += 1
		elif ans[i - 1] == '':
			ans[i - 1] = c
			visited[c] = True
			i -= 1
		else:
			ok = False
			break
	if ok:
		print('YES')
		for start in range(53):
			if ans[start] != '':
				break
		j = start - 1
		for c in string.ascii_lowercase:
			if visited[c] == False:
				ans[j] = c
				j -= 1
		print(''.join(ans[j + 1:j + 1 + 26]))
	else:
		print('NO')


from string import ascii_lowercase

def main():
	t = int(input())
	for __ in range(t):
		s = input()
		pos = 0
		used = [False] * 26
		used[ord(s[0]) - 97] = True
		t = []
		t.append(s[0])
		flag = False
		for i in range(1, len(s)):
			if used[ord(s[i]) - 97]:
				if pos > 0 and t[pos - 1] == s[i]:
					pos -= 1
				elif pos + 1 < len(t) and t[pos + 1] == s[i]:
					pos += 1
				else:
					print('NO')
					flag = True
					break
			else:
				if pos == 0:
					t.insert(0, s[i])
				elif pos == len(t) - 1:
					t.append(s[i])
					pos += 1
				else:
					print('NO')
					flag = True
					break
				used[ord(s[i]) - 97] = True
		if not flag:
			print('YES')
			for letter in ascii_lowercase:
				if not used[ord(letter) - 97]:
					t.append(letter)
			print(''.join(t))
main()


T = int(input())
for _ in range(T):
	s = input()
	kb = ''
	i = -1
	used = set()
	ok = True
	for c in s:
		if kb == '':
			kb = c
			used.add(c)
			i = 0
		elif c in used:
			if i + 1 < len(kb) and kb[i + 1] == c:
				i += 1
			elif i > 0 and kb[i - 1] == c:
				i -= 1
			else:
				ok = False
				break
		elif i == len(kb) - 1:
			kb += c
			i += 1
			used.add(c)
		elif i == 0:
			kb = c + kb
			used.add(c)
		else:
			ok = False
			break
	if ok:
		print('YES')
		for c in range(ord('a'), ord('z') + 1):
			if chr(c) not in kb:
				kb += chr(c)
		print(kb)
	else:
		print('NO')


import string

def main():
	line = input()
	our_line = line[0]
	if len(line) == 1:
		print('YES')
		print(string.ascii_lowercase)
		return
	for i in range(0, len(line) - 1):
		if line[i] in our_line:
			ind = our_line.index(line[i])
		else:
			ind = -1
		if ind != -1:
			if len(our_line) == 1:
				our_line += line[i + 1]
			elif ind == 0:
				if our_line[1] != line[i + 1]:
					if line[i + 1] in our_line:
						print('NO')
						return
					our_line = line[i + 1] + our_line
			elif ind == len(our_line) - 1:
				if our_line[ind - 1] != line[i + 1]:
					if line[i + 1] in our_line:
						print('NO')
						return
					our_line = our_line + line[i + 1]
			elif not (our_line[ind - 1] == line[i + 1] or our_line[ind + 1] == line[i + 1]):
				print('NO')
				return
	print('YES')
	for letter in string.ascii_lowercase:
		if not letter in our_line:
			our_line += letter
	print(our_line)
t = int(input())
for i in range(t):
	main()


import string
import collections

def perfectKeyBoard(S):
	letters = set(string.ascii_lowercase)
	used = set()
	queue = collections.deque()
	ptr = 0
	for ch in S:
		if not queue:
			queue.append(ch)
			used.add(ch)
			letters.remove(ch)
			ptr = 0
		elif ch in used:
			if ptr + 1 < len(queue) and queue[ptr + 1] == ch:
				ptr += 1
			elif ptr - 1 >= 0 and queue[ptr - 1] == ch:
				ptr -= 1
			else:
				print('NO')
				return
		elif ch not in used:
			if ptr == 0 and len(queue) > 1:
				queue.appendleft(ch)
				used.add(ch)
				letters.remove(ch)
			elif ptr == len(queue) - 1:
				queue.append(ch)
				used.add(ch)
				letters.remove(ch)
				ptr = len(queue) - 1
			else:
				print('NO')
				return
	print('YES')
	keyboard = ''.join(queue) + ''.join(list(letters))
	print(keyboard)
inputCount = int(input())
for _ in range(inputCount):
	perfectKeyBoard(input())


from math import *
t = int(input())
dd = [chr(97 + i) for i in range(26)]
while t:
	t -= 1
	s = input()
	if len(s) == 1:
		print('YES')
		for i in dd:
			print(i, end='')
		print()
		continue
	re = [s[0], s[1]]
	p = 0
	sr = set(s[:2])
	flag = 0
	pr = 1
	for i in s[2:]:
		c = 0
		try:
			if re[pr - 1] == i and pr - 1 != -1:
				pr = pr - 1
				continue
			else:
				c += 1
		except:
			c += 1
		try:
			if re[pr + 1] == i:
				pr = pr + 1
				continue
			else:
				c += 1
		except:
			c += 1
		if c == 2:
			if i in sr or (pr > 0 and pr < len(re) - 1):
				flag = 3
				break
			if pr == 0:
				re.insert(0, i)
				pr = 0
			else:
				re.insert(pr + 1, i)
				pr += 1
			sr.add(i)
		else:
			continue
	if flag == 3:
		print('NO')
	else:
		print('YES')
		for i in re:
			print(i, end='')
		for i in dd:
			if i not in sr:
				print(i, end='')
		print()


for _ in range(int(input())):
	s = input()
	d = {}
	for i in range(26):
		d[chr(97 + i)] = set()
	for i in range(len(s) - 1):
		d[s[i]].add(s[i + 1])
		d[s[i + 1]].add(s[i])
	k1 = 0
	k2 = 0
	k3 = 0
	l1 = set()
	l2 = set()
	s1 = ''
	for i in d:
		if len(d[i]) == 1:
			k1 += 1
			l1.add(i)
		elif len(d[i]) == 2:
			k2 += 1
			l2.add(i)
		elif len(d[i]) != 0:
			k3 += 1
	v = [0] * 26
	if len(s) == 1:
		s1 += s
		for i in d:
			if i != s:
				s1 += i
		print('YES')
		print(s1)
	elif k3 == 0 and k1 >= 1:
		t = l1.pop()
		s1 += t
		v[97 - ord(t)] = 1
		q = []
		q.append(t)
		while len(q) > 0:
			for i in d[q.pop(0)]:
				if v[97 - ord(i)] == 0:
					s1 += i
					v[97 - ord(i)] = 1
					q.append(i)
		for i in d:
			if len(d[i]) == 0:
				s1 += i
		print('YES')
		print(s1)
	else:
		print('NO')


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

def addEdge(a, b):
	graph[a].append(b)
	graph[b].append(a)
	graph[a] = list(set(graph[a]))
	graph[b] = list(set(graph[b]))

def Bfs(src):
	st = ''
	q = deque([])
	q.append(src)
	visited[src] = True
	st += src
	while q:
		node = q.popleft()
		for neighbour in graph[node]:
			if not visited[neighbour]:
				q.append(neighbour)
				st += neighbour
				visited[neighbour] = True
	return st
t = ip()
for _ in range(t):
	s = ips()
	n = len(s)
	graph = dd(list)
	ch = 'abcdefghijklmnopqrstuvwxyz'
	if n == 1:
		ans = ch
		out('YES')
		out(ans)
	else:
		visited = dd(bool)
		for i in range(n):
			if i == 0:
				(a, b) = (s[i], s[i + 1])
				if a != b:
					addEdge(a, b)
			elif i == n - 1:
				(a, b) = (s[i], s[i - 1])
				if a != b:
					addEdge(a, b)
			else:
				(a, b) = (s[i], s[i + 1])
				if a != b:
					addEdge(a, b)
				(a, b) = (s[i], s[i + 1])
				if a != b:
					addEdge(a, b)
		flag = True
		for i in set(s):
			if len(graph[i]) > 2:
				flag = False
				break
		ct = []
		for i in graph:
			if len(graph[i]) == 1:
				ct.append(i)
		if len(ct) != 2:
			flag = False
		if flag:
			st = ct[0]
			end = ct[1]
			ans = Bfs(st)
			if visited[end]:
				out('YES')
				for i in ch:
					if i not in ans:
						ans += i
				out(ans)
			else:
				out('NO')
		else:
			out('NO')


for t in range(int(input())):
	g = [set() for i in range(26)]
	s = input()
	for i in range(1, len(s)):
		c = s[i - 1]
		d = s[i]
		g[ord(c) - ord('a')].add(ord(d) - ord('a'))
		g[ord(d) - ord('a')].add(ord(c) - ord('a'))
	b = [False] * 26
	r = []
	possible = True
	for i in range(26):
		if len(g[i]) > 2:
			possible = False

	def run(i):
		if b[i]:
			return
		if len(g[i]) > 2:
			possible = False
		elif len(g[i]) == 1:
			r.append(chr(i + ord('a')))
			b[i] = True
			for j in g[i]:
				g[j].remove(i)
				g[i] = []
				run(j)
		elif len(g[i]) == 0:
			r.append(chr(i + ord('a')))
			b[i] = True
	for i in range(26):
		run(i)
	if len(r) == 26 and possible:
		print('YES')
		print(''.join(r))
	else:
		print('NO')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		s = S()
		if len(s) == 1:
			rr.append('YES')
			rr.append(string.ascii_lowercase)
			continue
		d = collections.defaultdict(set)
		for (a, b) in zip(s, s[1:]):
			d[a].add(b)
			d[b].add(a)
		u = set()
		r = []
		for (k, v) in list(d.items()):
			if len(v) > 2:
				break
			if k in u:
				continue
			if len(v) != 1:
				continue
			r.append(k)
			u.add(k)
			nk = list(v)[0]
			while 1:
				r.append(nk)
				u.add(nk)
				nv = d[nk]
				if len(nv) == 1:
					break
				for nnk in nv:
					if nnk == k:
						continue
					k = nk
					nk = nnk
					break
		if len(r) != len(d):
			rr.append('NO')
		else:
			for c in string.ascii_lowercase:
				if c not in u:
					r.append(c)
			rr.append('YES')
			rr.append(JA(r, ''))
	return JA(rr, '\n')
print(main())


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import ceil
MOD = pow(10, 9) + 7
lol = 'abcdefghijklmnopqrstuvwxzy'
test = int(input())
for _ in range(test):
	string = input()
	if len(string) == 1:
		result = string
		for c in lol:
			if c != string:
				result += c
		print('YES')
		print(result)
	else:
		dicti = {}
		for i in range(len(string)):
			if i != '\\n':
				listi = []
				if i - 1 >= 0:
					listi.append(string[i - 1])
				if i + 1 < len(string):
					listi.append(string[i + 1])
				if string[i] in dicti:
					for items in listi:
						dicti[string[i]].append(items)
				else:
					dicti[string[i]] = listi
		flag = True
		count = 0
		for i in dicti:
			hehe = list(set(dicti[i]))
			dicti[i] = hehe
			if len(hehe) == 1:
				count += 1
		if count != 2:
			print('NO')
		else:
			added = set([])
			password = [-1] * len(dicti)
			for i in dicti:
				if len(dicti[i]) == 1:
					if password[0] == -1:
						password[0] = i
						password[1] = dicti[i][0]
					elif password[-1] == -1:
						password[-1] = i
						password[-2] = dicti[i][0]
					added.add(i)
					added.add(dicti[i][0])
			(ptr1, ptr2) = (1, -2)
			while len(added) != len(dicti):
				chars = dicti[password[ptr1]]
				for char in chars:
					if char not in added:
						password[ptr1 + 1] = char
						ptr1 += 1
						added.add(char)
				chars = dicti[password[ptr2]]
				for char in chars:
					if char not in added:
						password[ptr2 - 1] = char
						ptr2 -= 1
						added.add(char)
			for c in range(97, 123):
				if chr(c) not in added:
					password.append(chr(c))
			result = ''
			for i in password:
				result += i
			print('YES')
			print(result)


t = int(input())
for j in range(t):
	d = {'a': set(), 'b': set(), 'c': set(), 'd': set(), 'e': set(), 'f': set(), 'g': set(), 'h': set(), 'i': set(), 'j': set(), 'k': set(), 'l': set(), 'm': set(), 'n': set(), 'o': set(), 'p': set(), 'q': set(), 'r': set(), 's': set(), 't': set(), 'u': set(), 'v': set(), 'w': set(), 'x': set(), 'y': set(), 'z': set()}
	s = input()
	if len(s) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
	else:
		for i in range(1, len(s)):
			d[s[i]].add(s[i - 1])
			d[s[i - 1]].add(s[i])
		bul = True
		ans = ''
		str = ''
		for (key, val) in d.items():
			if len(val) > 2:
				bul = False
				break
			elif len(val) == 1:
				ans = key
			elif len(val) == 0:
				str += key
		if not bul or ans == '':
			print('NO')
		else:
			now_el = d[ans].pop()
			while len(d[now_el]) == 2:
				for el in d[now_el]:
					if el != ans[-1]:
						ans += now_el
						now_el = el
						break
			ans += now_el
			print('YES')
			print(ans + str)


for i in range(int(input())):
	l = list(input())
	s = []
	c = 0
	k = 'abcdefghijklmnopqrstuvwxyz'
	for i in range(len(l)):
		if len(s) == 0:
			s.append(l[i])
		elif l[i] not in s:
			if s[-1] == l[i - 1]:
				s.append(l[i])
			elif s[0] == l[i - 1]:
				s = l[i:i + 1] + s
			else:
				print('NO')
				c += 1
				break
		elif l[i] in s:
			j = s.index(l[i])
			if j == 0:
				if s[j + 1] != l[i - 1]:
					print('NO')
					c += 1
					break
			elif j == len(s) - 1:
				if s[j - 1] != l[i - 1]:
					print('NO')
					c += 1
					break
			elif s[j + 1] != l[i - 1] and s[j - 1] != l[i - 1]:
				print('NO')
				c += 1
				break
	if c == 0:
		for i in range(len(k)):
			if k[i] not in s:
				s.append(k[i])
		print('YES', ''.join(s), sep='\n')


alf = 'abcdefghijklmnopqrstuvwxyz'
for _ in [0] * int(input()):
	s = input()
	key = s[0]
	ans = 'YES'
	for i in range(len(s) - 1):
		if s[i + 1] not in key:
			x = key.find(s[i])
			if x == len(key) - 1:
				key += s[i + 1]
			elif x == 0:
				key = s[i + 1] + key
			else:
				ans = 'NO'
				break
		else:
			x1 = key.find(s[i + 1])
			x2 = key.find(s[i])
			if abs(x1 - x2) > 1:
				ans = 'NO'
				break
	print(ans)
	if ans == 'YES':
		for i in alf:
			if i not in key:
				key += i
		print(key)


from collections import *
for _ in range(int(input())):
	d = deque()
	s = input()
	ch = 1
	j = 0
	a = [0] * 26
	d.append(s[0])
	a[ord(s[0]) - 97] = 1
	for i in s[1:]:
		if a[ord(i) - 97] == 0:
			if len(d) == 1:
				d.append(i)
				a[ord(i) - 97] = 1
				j += 1
			elif j == 0:
				d.appendleft(i)
				a[ord(i) - 97] = 1
				j = 0
			elif j == len(d) - 1:
				d.append(i)
				a[ord(i) - 97] = 1
				j += 1
			else:
				ch = 0
				break
		elif len(d) != 0:
			if d[j] == i:
				continue
			elif j == 0:
				if d[j + 1] == i:
					j += 1
				else:
					ch = 0
					break
			elif j == len(d) - 1:
				if d[j - 1] == i:
					j -= 1
				else:
					ch = 0
					break
			elif d[j] == i:
				continue
			elif d[j + 1] == i:
				j += 1
			elif d[j - 1] == i:
				j -= 1
			else:
				ch = 0
				break
		else:
			continue
	if ch == 0:
		print('NO')
	else:
		s = ''
		for i in d:
			s += i
			a[ord(i) - 97] = 1
		p = 'abcdefghijklmnopqrstuvwxyz'
		for i in p:
			if a[ord(i) - 97] == 1:
				continue
			else:
				s += i
		print('YES')
		print(s)


from collections import deque
from collections import defaultdict
t = int(input())
for _ in range(t):
	sl = list(input())
	ansl = deque()
	target = 0
	use = defaultdict(int)
	for s in sl:
		if len(ansl) == 0:
			ansl.append(s)
			use[s] = 1
			continue
		if target < len(ansl) - 1 and ansl[target + 1] == s:
			target += 1
			continue
		if target > 0 and ansl[target - 1] == s:
			target -= 1
			continue
		if target == 0:
			if use[s] == 1:
				print('NO')
				break
			ansl.appendleft(s)
			use[s] = 1
			continue
		if target == len(ansl) - 1:
			if use[s] == 1:
				print('NO')
				break
			ansl.append(s)
			use[s] = 1
			target += 1
			continue
		print('NO')
		break
	else:
		print('YES')
		ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
		for s in ascii_lowercase:
			if use[s] == 0:
				ansl.append(s)
		print(''.join(ansl))


from sys import stdin, stdout
import traceback
read = stdin.readline
write = stdout.write
writeln = lambda x: write(str(x) + '\n')

def reads(typ=int):
	return list(map(typ, read().split()))

class Sol:

	@classmethod
	def input(cls):
		s = cls()
		return s

	def solve(self):
		alphabets = 'abcdefghijklmnopqrstuvwxyz'
		s = read().strip()
		set_pass = set(s)
		other = [a for a in alphabets if a not in set_pass]
		q = ['0'] * 80
		i = 30
		q[i] = s[0]
		used = set(s[0])
		for c in s[1:]:
			if q[i + 1] == c:
				i += 1
			elif q[i - 1] == c:
				i -= 1
			elif q[i + 1] == '0' and c not in used:
				q[i + 1] = c
				i += 1
				used.add(c)
			elif q[i - 1] == '0' and c not in used:
				q[i - 1] = c
				i -= 1
				used.add(c)
			else:
				return ''
		return ''.join([x for x in q if x != '0'] + other)
try:
	for _ in range(int(read())):
		x = Sol.input().solve()
		if x:
			writeln('YES')
			writeln(x)
		else:
			writeln('NO')
except Exception as e:
	print('Got exception:', repr(e))
	print(traceback.format_exc())


from collections import defaultdict
from string import ascii_lowercase

def solve(tok: str):
	if len(tok) == 1:
		return ascii_lowercase
	incident_chr = defaultdict(set)
	for i in range(len(tok)):
		if i == 0:
			incident_chr[tok[i]].add(tok[i + 1])
		elif i == len(tok) - 1:
			incident_chr[tok[i]].add(tok[i - 1])
		else:
			incident_chr[tok[i]].add(tok[i + 1])
			incident_chr[tok[i]].add(tok[i - 1])
	tokens = []
	used = set()
	if any((len(incident_chr[k]) > 2 for k in incident_chr)):
		return None
	for (k, friends) in incident_chr.items():
		if k in used:
			continue
		if len(friends) == 2:

			def gen_tok(e: str) -> str:
				used.add(e)
				(l, r) = list(incident_chr[e])
				v = l + e + r
				used.add(l)
				while len(incident_chr[l]) == 2:
					(ll, lr) = list(incident_chr[l])
					if ll not in used:
						v = ll + v
						l = ll
					elif lr not in used:
						v = lr + v
						l = lr
					else:
						return ''
					used.add(l)
				used.add(r)
				while len(incident_chr[r]) == 2:
					(rl, rr) = list(incident_chr[r])
					if rl not in used:
						v = v + rl
						r = rl
					elif rr not in used:
						v = v + rr
						r = rr
					else:
						return ''
					used.add(r)
				return v
			partial_value = gen_tok(k)
			if not partial_value:
				return None
			tokens.append(partial_value)
	for (k, friends) in incident_chr.items():
		if k in used:
			continue
		f = list(friends)[0]
		used.add(k)
		used.add(f)
		tokens.append(k + f)
	base = ''.join(tokens) if tokens else ''
	for e in ascii_lowercase:
		if e in used:
			continue
		base += e
	for i in range(len(tok)):
		if i == 0:
			if abs(base.index(tok[i]) - base.index(tok[i + 1])) > 1:
				return None
		elif i == len(tok) - 1:
			if abs(base.index(tok[i]) - base.index(tok[i - 1])) > 1:
				return None
		else:
			if abs(base.index(tok[i]) - base.index(tok[i + 1])) > 1:
				return None
			if abs(base.index(tok[i]) - base.index(tok[i - 1])) > 1:
				return None
	return base
for _ in range(int(input())):
	s = input()
	res = solve(s)
	if res:
		print('YES\n{}'.format(res))
	else:
		print('NO')


T = int(input())
for t in range(T):
	s = input().strip()
	r = s[:2]
	p = 1
	for i in range(2, len(s)):
		if p and s[i] == r[p - 1]:
			p -= 1
		elif p < len(r) - 1 and s[i] == r[p + 1]:
			p += 1
		elif not p:
			r = s[i] + r
		elif p == len(r) - 1:
			r += s[i]
			p += 1
		else:
			print('NO')
			break
	else:
		for i in 'abcdefghijklmnopqrstuvwxyz':
			if i not in r:
				r += i
		if len(r) == 26:
			print('YES')
			print(r)
		else:
			print('NO')


t = int(input())
for _ in range(t):
	s = str(input())
	n = len(s)
	if n == 1:
		ans = ''
		for i in range(26):
			ans += chr(i + ord('a'))
		print('YES')
		print(ans)
		continue
	g = [set() for _ in range(26)]
	for i in range(n - 1):
		j = i + 1
		num_i = ord(s[i]) - ord('a')
		num_j = ord(s[j]) - ord('a')
		g[num_i].add(num_j)
		g[num_j].add(num_i)
	node = 0
	edge = 0
	flag = False
	for i in range(26):
		if len(g[i]) != 0:
			node += 1
			if len(g[i]) == 1:
				edge += len(g[i])
				i_ = i
			elif len(g[i]) == 2:
				edge += len(g[i])
			else:
				flag = True
	edge = edge // 2
	if node - 1 != edge:
		flag = True
	if flag:
		print('NO')
		continue
	else:
		print('YES')
	from collections import deque
	q = deque()
	q.append(i_)
	visit = [-1] * 26
	visit[i_] = 1
	ans = ''
	while q:
		x = q.popleft()
		ans += chr(x + ord('a'))
		for new_x in g[x]:
			if visit[new_x] == -1:
				q.append(new_x)
				visit[new_x] = 1
	for i in range(26):
		if visit[i] == -1:
			ans += chr(i + ord('a'))
	print(ans)


from collections import defaultdict
import math
for _ in range(int(input())):
	S = input()
	L = []
	p = -1
	FLAG = 0
	for i in S:
		if len(L) < 2:
			L.append(i)
			p += 1
		elif len(L) - 2 >= p and L[p + 1] == i:
			p += 1
		elif p > 0 and L[p - 1] == i:
			p -= 1
		elif p == 0 and i not in L:
			L.insert(0, i)
			p = 0
		elif p == len(L) - 1 and i not in L:
			L.append(i)
			p += 1
		else:
			FLAG = 1
			break
	A = 'abcdefghijklmnopqrstuvwxyz'
	L.reverse()
	if FLAG == 1:
		print('NO')
	else:
		print('YES')
		for i in A:
			if i not in L:
				L.append(i)
		print(''.join(L))


n = int(input())
c2n = lambda x: ord(x) - ord('a')
n2c = lambda x: chr(97 + x)
for q in range(n):
	s = input()
	e = []
	for i in range(26):
		e.append([])
	fail = False
	for i in range(len(s)):
		c = c2n(s[i])
		if i != 0:
			l = c2n(s[i - 1])
			if l not in e[c]:
				e[c].append(l)
			if c not in e[l]:
				e[l].append(c)
		if i != len(s) - 1:
			r = c2n(s[i + 1])
			if r not in e[c]:
				e[c].append(r)
			if c not in e[r]:
				e[r].append(c)
	visited = [False] * 26
	res = ''
	for i in range(i):
		if len(s[i]) > 3:
			print('NO')
			continue
	for i in range(26):
		if visited[i]:
			continue
		if len(e[i]) == 0:
			res += n2c(i)
			visited[i] = True
			continue
		if len(e[i]) == 2:
			continue
		visited[i] = True
		res += n2c(i)
		cur = e[i][0]
		while True:
			visited[cur] = True
			res += n2c(cur)
			if len(e[cur]) == 1:
				break
			cur = e[cur][0] if visited[e[cur][1]] is True else e[cur][1]
			if visited[cur]:
				fail = True
				res = ''
				break
		if fail:
			break
	if len(res) != 26:
		print('NO')
		continue
	if fail:
		continue
	print('YES')
	print(res)


test = int(input())
for _ in range(test):
	passwd = input()
	dic = {passwd[0]: 0}
	res_dic = {0: passwd[0]}
	pointer = 1
	key = True
	alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'y', 'z', 'q', 'x', 'w']
	alph.remove(passwd[0])
	while pointer <= len(passwd) - 1:
		if passwd[pointer] not in dic:
			prev = dic[passwd[pointer - 1]]
			if prev + 1 not in dic.values():
				dic[passwd[pointer]] = prev + 1
				res_dic[prev + 1] = passwd[pointer]
				alph.remove(passwd[pointer])
			elif prev - 1 not in dic.values():
				dic[passwd[pointer]] = prev - 1
				res_dic[prev - 1] = passwd[pointer]
				alph.remove(passwd[pointer])
			else:
				print('NO')
				key = False
				break
		elif abs(dic[passwd[pointer - 1]] - dic[passwd[pointer]]) != 1:
			print('NO')
			key = False
			break
		pointer += 1
	if key == True:
		print('YES')
		arr = sorted(res_dic)
		res = ''
		for i in arr:
			res += res_dic[i]
		for j in alph:
			res += j
		print(res)


import sys
input = sys.stdin.readline
T = int(input())

def dfs(u):
	global ans, flag
	ans += chr(u + 97)
	for v in adj[u]:
		if not vst[v]:
			vst[v] = True
			for q in adj[v]:
				if vst[q] and q != u:
					flag = False
			dfs(v)
for _ in range(T):
	X = input().rstrip()
	adj = [set() for _ in range(26)]
	N = len(X)
	for i in range(N - 1):
		(a, b) = (X[i], X[i + 1])
		adj[ord(a) - 97].add(ord(b) - 97)
		adj[ord(b) - 97].add(ord(a) - 97)
	if N == 1:
		print('YES')
		for i in range(26):
			print(chr(i + 97), end='')
		print()
		continue
	one = []
	flag = True
	a2 = 0
	for i in range(26):
		k = adj[i]
		if len(k) == 0:
			a2 += 1
		elif len(k) == 1:
			one.append(i)
		elif len(k) > 2:
			flag = False
	if not one:
		print('NO')
		continue
	ans = ''
	vst = [False] * 26
	if len(one) != 2:
		flag = False
	vst[one[0]] = True
	dfs(one[0])
	a1 = 0
	for i in range(26):
		if not vst[i]:
			a1 += 1
			ans += chr(i + 97)
	if flag and a1 == a2:
		print('YES')
		print(ans)
	else:
		print('NO')


t = int(input())
for i in range(t):
	sl = {}
	for j in 'qazwsxedcrfvtgbyhnujmikolp':
		sl[j] = set()
	s = input()
	if len(s) == 1:
		print('YES')
		print('qazwsxedcrfvtgbyhnujmikolp')
		continue
	sl[s[0]].add(s[1])
	for j in range(1, len(s) - 1):
		sl[s[j]].add(s[j - 1])
		sl[s[j]].add(s[j + 1])
	sl[s[-1]].add(s[-2])
	f = False
	cnt = 0
	for j in sl.keys():
		if len(sl[j]) > 2:
			f = True
			break
		if len(sl[j]) == 1:
			cnt += 1
	if f or cnt != 2:
		print('NO')
		continue
	print('YES')
	ans = []
	ans2 = []
	ans3 = []
	for j in sl.keys():
		if len(sl[j]) == 1:
			ans.append(j)
		elif len(sl[j]) == 2:
			ans2.append(j)
		else:
			ans3.append(j)
		sl[j] = list(sl[j])
	(s1, s2) = ans
	if s1 != s[-1] and s1 != s[0]:
		(s1, s2) = (s2, s1)
	ans = s1
	cur = s1
	used = set(s1)
	while cur != s2:
		if sl[cur][0] in used:
			cur = sl[cur][-1]
		else:
			cur = sl[cur][0]
		used.add(cur)
		ans += cur
	print(ans, ''.join(ans3), sep='')


import sys
import math
input = sys.stdin.readline

def bo(i):
	return ord(i) - ord('a')
t = int(input())
while t > 0:
	t -= 1
	s = list(input().rstrip())
	a = [[] for i in range(27)]
	vis = [[0 for i in range(27)] for j in range(27)]
	n = len(s)
	for i in range(n - 1):
		if vis[bo(s[i])][bo(s[i + 1])] == 0:
			vis[bo(s[i])][bo(s[i + 1])] = 1
			vis[bo(s[i + 1])][bo(s[i])] = 1
			a[bo(s[i])].append(bo(s[i + 1]))
			a[bo(s[i + 1])].append(bo(s[i]))
	flag = 0
	for i in range(n):
		if len(a[bo(s[i])]) > 2:
			flag = 1
			break
	if flag == 1:
		print('NO')
		continue
	q = 'abcdefghijklmnopqrstuvwxyz'
	v = [0 for i in range(27)]
	fi = 0
	z = -9
	uu = ''
	if len(set(s)) == 1:
		print('YES')
		print(q)
		continue
	while fi < 5:
		if z == -9:
			for i in range(27):
				if len(a[i]) == 1:
					uu += q[i]
					z = a[i][0]
					v[i] = 1
					break
		else:
			if len(a[z]) == 1:
				uu += q[z]
				v[z] = 1
				break
			elif v[a[z][0]] == 1 and v[a[z][1]] == 1:
				uu += q[z]
				v[z] = 1
				break
			v[z] = 1
			for j in a[z]:
				if v[j] == 0:
					uu += q[z]
					z = j
					v[j] = 1
					break
		if z == -9:
			fi = -9
			break
	for i in q:
		if v[bo(i)] == 0:
			uu += i
	if fi == -9:
		print('NO')
		continue
	print('YES')
	print(uu)


def solve():
	s = input()
	dic = dict([(chr(i), 0) for i in range(97, 123)])
	s1 = s[0]
	pos = 0
	dic[s[0]] = 1
	for i in range(1, len(s)):
		if dic[s[i]]:
			if pos > 0 and s1[pos - 1] == s[i]:
				pos -= 1
			elif pos + 1 < len(s1) and s1[pos + 1] == s[i]:
				pos += 1
			else:
				print('NO')
				return
		elif pos == 0:
			s1 = s[i] + s1
		elif pos == len(s1) - 1:
			s1 += s[i]
			pos += 1
		else:
			print('NO')
			return
		dic[s[i]] = 1
	for i in range(26):
		if dic[chr(97 + i)] == 0:
			s1 += chr(97 + i)
	print('YES')
	print(s1)
t = int(input())
while t:
	solve()
	t -= 1


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

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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')
import time
start_time = time.time()
import collections as col

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	S = getStr()
	if len(S) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		return
	graph = col.defaultdict(set)
	for i in range(len(S) - 1):
		graph[S[i]].add(S[i + 1])
		graph[S[i + 1]].add(S[i])
	ones = []
	for key in graph:
		if len(graph[key]) > 2:
			print('NO')
			return
		if len(graph[key]) == 1:
			ones.append(key)
	nodes = set()
	for j in range(26):
		nodes.add(chr(ord('a') + j))

	def bfs(graph, visited, node, queue, nodes):
		visited.append(node)
		visited_dict = {node: node}
		nodes.remove(node)
		queue.append((node, None))
		queue = col.deque(queue)
		cycle = False
		while queue:
			(s, parent) = queue.popleft()
			for neighbour in graph[s]:
				if neighbour in visited_dict and neighbour != parent:
					cycle = True
				elif neighbour not in visited_dict:
					visited.append(neighbour)
					visited_dict[neighbour] = neighbour
					nodes.remove(neighbour)
					queue.append((neighbour, s))
		return (cycle, nodes, visited)
	connected_components = []
	if not ones:
		print('NO')
		return
	while nodes and ones:
		node = ones.pop()
		if node not in nodes:
			continue
		(ans, nodes, visited) = bfs(graph, [], node, [], nodes)
		if ans:
			print('NO')
			return
		connected_components.append(visited)
	ans = ''
	for c in connected_components:
		ans += ''.join(visited)
	for x in nodes:
		ans += x
	print('YES')
	print(ans)
	return
for _ in range(getInt()):
	solve()


import sys
input = sys.stdin.readline
from collections import deque
t = int(input())
for _ in range(t):
	s = input().rstrip()
	n = len(s)
	ls = [0] * 51
	ls[25] = s[0]
	st = set(s[0])
	flg = 1
	l = 25
	r = 25
	now = 25
	for i in range(1, n):
		if s[i] not in st:
			if ls[l] == s[i - 1]:
				ls[l - 1] = s[i]
				l -= 1
				now -= 1
			elif s[i - 1] == ls[r]:
				ls[r + 1] = s[i]
				r += 1
				now += 1
			else:
				print('NO')
				flg = 0
				break
			st.add(s[i])
		elif ls[now - 1] == s[i]:
			now -= 1
		elif ls[now + 1] == s[i]:
			now += 1
		else:
			print('NO')
			flg = 0
			break
	if flg:
		print('YES')
		for i in range(l, r + 1):
			print(ls[i], end='')
		for i in range(97, 97 + 26):
			if chr(i) not in st:
				print(chr(i), end='')
		print('')


from collections import deque
n = int(input())
for i in range(n):
	string = input()
	lis = deque([])
	pointer = -1
	se = set()
	flag = 0
	check = 'abcdefghijklmnopqrstuvwxyz'
	for i in string:
		if len(lis) == 0:
			pointer = 0
			lis.append(i)
			se.add(i)
			continue
		if i not in se:
			se.add(i)
			if pointer + 1 < len(lis) and pointer - 1 >= 0:
				print('NO')
				flag = 1
				break
			if pointer + 1 < len(lis):
				lis.appendleft(i)
				pointer = 0
				continue
			else:
				lis.append(i)
				pointer += 1
				continue
		else:
			if pointer + 1 < len(lis):
				if lis[pointer + 1] == i:
					pointer += 1
					continue
			if pointer - 1 >= 0:
				if lis[pointer - 1] == i:
					pointer -= 1
					continue
			flag = 1
			print('NO')
			break
	if flag == 1:
		continue
	for i in check:
		if i not in se:
			lis.append(i)
	print('YES')
	print(''.join(lis))


from string import ascii_lowercase
t = int(input())
for _ in range(t):
	unused = set()
	for c in ascii_lowercase:
		unused.add(c)
	s = input().strip()
	keyword = [s[0]]
	unused.discard(s[0])
	j = 0
	no = False
	for i in range(1, len(s)):
		if j + 1 < len(keyword) and keyword[j + 1] == s[i]:
			j += 1
		elif j - 1 >= 0 and keyword[j - 1] == s[i]:
			j -= 1
		elif j + 1 == len(keyword) and s[i] in unused:
			keyword.append(s[i])
			j += 1
		elif j - 1 == -1 and s[i] in unused:
			keyword = [s[i]] + keyword
		else:
			print('NO')
			no = True
			break
		unused.discard(s[i])
	if not no:
		for c in unused:
			keyword.append(c)
		print('YES')
		print(''.join(keyword))


def main():
	for _ in range(int(input())):
		s = input()
		ok = True
		ans = []
		j = -1
		idx = {}
		for i in range(len(s)):
			if s[i] not in ans:
				if j == len(ans) - 2:
					ans.append(s[i])
					j += 1
				elif j == -1:
					ans = [s[i]] + ans
				else:
					ok = False
			else:
				if j > -1:
					if ans[j - 1 + 1] == s[i]:
						j -= 1
						continue
				if j < len(ans) - 1 - 1:
					if ans[j + 1 + 1] == s[i]:
						j += 1
						continue
				ok = False
		if ok:
			for i in range(97, 97 + 26):
				if chr(i) not in ans:
					ans.append(chr(i))
			print('YES')
			print(''.join(ans))
		else:
			print('NO')
main()


import sys
from collections import defaultdict

def can(dic, start):
	vis = defaultdict(int)
	q = [start]
	vis[start] = 1
	ans = start
	while q and len(ans) <= len(dic):
		let = q.pop(0)
		if len(dic[let]) > 2:
			return False
		if len(dic[let]) == 1:
			l = []
			for i in dic[let]:
				l.append(i)
			if vis[l[0]] == 1:
				if ans[0] == let:
					if ans[1] != l[0]:
						return False
				if ans[-1] == let:
					if ans[-2] != l[0]:
						return False
			else:
				vis[l[0]] = 1
				if ans[0] == let:
					ans = l[0] + ans
					q.append(l[0])
				elif ans[-1] == let:
					ans = ans + l[0]
					q.append(l[0])
				else:
					return False
		if len(dic[let]) == 2:
			l = []
			for i in dic[let]:
				l.append(i)
			if vis[l[0]] == 0 and vis[l[1]] == 0:
				if len(ans) == 1:
					ans = l[0] + ans + l[1]
					q.append(l[0])
					q.append(l[1])
					(vis[l[0]], vis[l[1]]) = (1, 1)
				else:
					return False
			elif vis[l[1]] == 1 and vis[l[0]] == 1:
				return False
			elif vis[l[1]] == 0 and vis[l[0]] == 1:
				if ans[0] == let:
					if ans[1] == l[0]:
						ans = l[1] + ans
					else:
						return False
				if ans[-1] == let:
					if ans[-2] == l[0]:
						ans = ans + l[1]
					else:
						return False
				q.append(l[1])
				vis[l[1]] = 1
			else:
				if ans[0] == let:
					if ans[1] == l[1]:
						ans = l[0] + ans
					else:
						return False
				if ans[-1] == let:
					if ans[-2] == l[0]:
						ans = ans + l[0]
					else:
						return False
				q.append(l[0])
				vis[l[0]] = 1
	return ans
t = int(sys.stdin.readline())
for _ in range(t):
	s = sys.stdin.readline()[:-1]
	l = 'abcdefghijklmnopqrstuvwxyz'
	if len(s) == 1:
		print('YES')
		print(l)
	else:
		dic = defaultdict(list)
		vis = defaultdict(int)
		ans = ''
		if s[1] not in dic[s[0]]:
			dic[s[0]].append(s[1])
		if s[0] not in dic[s[1]]:
			dic[s[1]].append(s[0])
		start = s[0]
		for i in range(1, len(s) - 1):
			if s[i - 1] not in dic[s[i]]:
				dic[s[i]].append(s[i - 1])
			if s[i + 1] not in dic[s[i]]:
				dic[s[i]].append(s[i + 1])
			if s[i] not in dic[s[i + 1]]:
				dic[s[i + 1]].append(s[i])
			if s[i] not in dic[s[i - 1]]:
				dic[s[i - 1]].append(s[i])
		if s[len(s) - 2] not in dic[s[len(s) - 1]]:
			dic[s[len(s) - 1]].append(s[len(s) - 2])
		if s[len(s) - 1] not in dic[s[len(s) - 2]]:
			dic[s[len(s) - 2]].append(s[len(s) - 1])
		ans = can(dic, s[0])
		if ans:
			print('YES')
			for i in l:
				if i not in ans:
					ans = i + ans
			print(ans)
		else:
			print('NO')


import sys

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

def hashChar(c):
	return ord(c[0]) - ord('a')

def unHashChar(val):
	return chr(ord('a') + val)

def compute(adjMatrix):
	adjList = [[] for i in range(0, 26)]
	ans = []
	for row_index in range(0, 26):
		for column_index in range(0, 26):
			if adjMatrix[row_index][column_index] == True:
				adjList[row_index].append(column_index)
	count_one_adj = 0
	one_adj_char = -1
	for i in range(0, len(adjList)):
		if len(adjList[i]) == 1:
			count_one_adj += 1
			if count_one_adj > 2:
				return ''
			one_adj_char = i
		elif len(adjList[i]) > 2:
			return ''
		if len(adjList[i]) == 0:
			ans.append(i)
	if count_one_adj != 2:
		return ''
	ans.append(one_adj_char)
	ans.append(adjList[one_adj_char][0])
	while len(adjList[ans[-1]]) == 2:
		if adjList[ans[-1]][0] != ans[-2]:
			ans.append(adjList[ans[-1]][0])
		else:
			ans.append(adjList[ans[-1]][1])
	return ''.join(map(lambda x: unHashChar(x), ans))
t = int(input())
for i in range(t):
	inp_str = input()
	if len(inp_str) == 1:
		print('YES')
		print(''.join(map(lambda x: unHashChar(x), list(range(0, 26)))))
		continue
	adjMatrix = [[False] * 26 for j in range(26)]
	for i in range(0, len(inp_str)):
		val = hashChar(inp_str[i])
		if i + 1 < len(inp_str):
			next_val = hashChar(inp_str[i + 1])
			adjMatrix[val][next_val] = True
			adjMatrix[next_val][val] = True
		if i - 1 >= 0:
			prv_val = hashChar(inp_str[i - 1])
			adjMatrix[val][prv_val] = True
			adjMatrix[prv_val][val] = True
	ans = compute(adjMatrix)
	if len(ans) > 0:
		print('YES')
		print(ans)
	else:
		print('NO')


def perfect_keyword(s):
	r = 'abcdefghijklmnopqrstuvwxyz'
	keyword = ''
	i = 0
	for a in s:
		if a in keyword:
			if i == 0:
				if a == keyword[1]:
					i += 1
				else:
					print('NO')
					return
			elif i == len(keyword) - 1:
				if a == keyword[i - 1]:
					i -= 1
				else:
					print('NO')
					return
			elif a == keyword[i - 1]:
				i -= 1
			elif a == keyword[i + 1]:
				i += 1
			elif a == keyword[i]:
				i = i
			else:
				print('NO')
				return
		else:
			if i != 0 and i != len(keyword) - 1:
				print('NO')
				return
			if i == 0:
				keyword = a + keyword
				i = 0
			else:
				keyword += a
				i += 1
	print('YES')
	for a in r:
		if a not in keyword:
			keyword += a
	print(keyword)
t = int(input())
L = []
for i in range(t):
	s = input()
	L.append(s)
for a in L:
	perfect_keyword(a)


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		ss = [ord(s) - ord('a') for s in list(input())]
		pos = [None] * 26
		pos[ss[0]] = 100
		last = ss[0]
		for s in ss[1:]:
			if pos[s]:
				if abs(pos[s] - pos[last]) != 1:
					print('NO')
					return
			elif not pos[last] + 1 in pos:
				pos[s] = pos[last] + 1
			elif not pos[last] - 1 in pos:
				pos[s] = pos[last] - 1
			else:
				print('NO')
				return
			last = s
		print('YES')
		mn = min([p for p in pos if p])
		res = [''] * 26
		for (i, p) in enumerate(pos):
			if p:
				res[p - mn] = chr(i + ord('a'))
		for (i, p) in enumerate(pos):
			if not p:
				res.append(chr(i + ord('a')))
		print(''.join(res))
	q = int(input())
	for _ in range(q):
		solve()
main()


def make(i, dir1=0):
	global neighs
	global ans
	used[i] = 1
	first = True
	if dir1 == 0:
		for letter in neighs[i]:
			if first:
				used[letter] = 1
				ans = letter + ans
				make(letter, -1)
				first = False
			else:
				used[letter] = 1
				ans += letter
				make(letter, 1)
	elif dir1 == -1:
		if len(neighs[i]) > 0:
			for letter in neighs[i]:
				if first and (not used[letter]):
					used[letter] = 1
					ans = ans[:ans.index(i)] + letter + ans[ans.index(i):]
					make(letter, -1)
					first = False
				elif not used[letter]:
					used[letter] = 1
					ans = ans[0:ans.index(i) + 1] + letter + ans[ans.index(i) + 1:]
					make(letter, 1)
	elif len(neighs[i]) > 0:
		for letter in neighs[i]:
			if first and (not used[letter]):
				used[letter] = 1
				ans = ans[0:ans.index(i) + 1] + letter + ans[ans.index(i) + 1:]
				make(letter, 1)
				first = False
			elif not used[letter]:
				used[letter] = 1
				ans = ans[:ans.index(i)] + letter + ans[ans.index(i):]
				make(letter, -1)

def isValid(s):
	s = ' ' + s + ' '
	for i in range(1, len(s) - 1):
		neighbors = [s[i - 1], s[i + 1]]
		for j in neighs[s[i]]:
			if j not in neighbors:
				return False
	return True
t = int(input())
for j in range(t):
	neighs = {'a': set(), 'b': set(), 'c': set(), 'd': set(), 'e': set(), 'f': set(), 'g': set(), 'h': set(), 'i': set(), 'j': set(), 'k': set(), 'l': set(), 'm': set(), 'n': set(), 'o': set(), 'p': set(), 'q': set(), 'r': set(), 's': set(), 't': set(), 'u': set(), 'v': set(), 'w': set(), 'x': set(), 'y': set(), 'z': set()}
	used = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0}
	s = input()
	if len(s) > 1:
		neighs[s[0]].add(s[1])
		neighs[s[len(s) - 1]].add(s[len(s) - 2])
		for i in range(1, len(s) - 1):
			neighs[s[i]].add(s[i - 1])
			neighs[s[i]].add(s[i + 1])
	counter = 0
	max1 = 0
	for i in neighs.keys():
		max1 = max(max1, len(neighs[i]))
		if len(neighs[i]) < 2:
			counter += 1
	first = True
	for i in neighs.keys():
		if first:
			ans = i
			make(i)
			first = False
		elif not used[i]:
			ans += i
			make(i, 1)
	if isValid(ans):
		print('YES')
		print(ans)
	else:
		print('NO')


import sys

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

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()

def get(x):
	return ord(x) - 97

def dfs(x):
	ans.append(x)
	for i in adj[x]:
		if i not in ans:
			k = dfs(i)
while t:
	t -= 1
	ans = []
	s = input()
	n = len(s)
	if n == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	adj = [set() for i in range(26)]
	for i in range(1, n):
		k = get(s[i])
		adj[k].add(get(s[i - 1]))
		adj[get(s[i - 1])].add(k)
	start = -1
	count = 0
	for i in range(26):
		if len(adj[i]) > 2:
			print('NO')
			break
		if len(adj[i]) == 1:
			start = i
	else:
		dfs(start)
		for i in range(26):
			if i not in ans:
				ans.append(i)
		ans = [chr(i + 97) for i in ans]
		for i in range(1, n):
			k = ans.index(s[i])
			m = ans.index(s[i - 1])
			if abs(k - m) != 1:
				print('NO')
				break
		else:
			print('YES')
			print(''.join(ans))


for _ in range(int(input())):
	s = input()
	p = s[0]
	c = ''
	q = 'abcdefghijklmnopqrstuvwxyz'
	flag = 0
	for i in range(1, len(s)):
		if s[i] in p:
			k = p.find(s[i])
			if len(p) == 1:
				if s[i] != p[0]:
					p += s[i]
			elif k == 0:
				if p[1] != s[i - 1]:
					flag = 1
					break
			elif k == len(p) - 1:
				if p[k - 1] != s[i - 1]:
					flag = 1
					break
			elif p[k - 1] != s[i - 1] and p[k + 1] != s[i - 1]:
				flag = 1
				break
		else:
			k = p.find(s[i - 1])
			if k == 0:
				c = p
				p = s[i]
				p += c
			elif k == len(p) - 1:
				p += s[i]
			else:
				flag = 1
				break
	if flag == 1:
		print('NO')
	else:
		print('YES')
		for i in q:
			if i not in p:
				p += i
		print(p)


tc = int(input())
while tc:
	s = input()
	visit = {}
	for i in range(26):
		visit[chr(ord('a') + i)] = 0
	if len(s) == 1:
		ans = []
		for i in visit:
			ans.append(i)
		print('YES')
		print(*ans, sep='')
		tc -= 1
		continue
	g = {}
	for i in range(len(s) - 1):
		if s[i] not in g:
			g[s[i]] = []
		if s[i + 1] not in g:
			g[s[i + 1]] = []
		g[s[i]].append(s[i + 1])
		g[s[i + 1]].append(s[i])
	se = []
	mx = -1
	for i in g:
		g[i] = list(set(g[i]))
		mx = max(mx, len(g[i]))
		if len(g[i]) == 1:
			se.append(i)
	if mx > 2 or len(se) != 2:
		print('NO')
	else:
		stak = [se[0]]
		ans = []
		while len(stak) != 0:
			node = stak.pop()
			visit[node] = 1
			ans.append(node)
			for i in g[node]:
				if visit[i] == 0:
					stak.append(i)
		print('YES')
		for i in visit:
			if visit[i] == 0:
				ans.append(i)
		print(*ans, sep='')
	tc -= 1


from sys import stdin, stdout

def dfs(u, res):
	if visit[u]:
		return
	visit[u] = True
	res.append(u)
	for v in adj[u]:
		if not visit[v]:
			dfs(v, res)
T = int(input())
for t in range(T):
	a = input()
	n = len(a)
	adj = [set() for _ in range(26)]
	for i in range(1, n):
		u = ord(a[i - 1]) - ord('a')
		v = ord(a[i]) - ord('a')
		adj[u].add(v)
		adj[v].add(u)
	deg_gt_2 = False
	for i in range(26):
		if len(adj[i]) > 2:
			deg_gt_2 = True
	if deg_gt_2:
		print('NO')
		continue
	visit = [False] * 26
	ans = []
	for u in range(26):
		if not visit[u] and len(adj[u]) == 1:
			res = []
			dfs(u, res)
			ans += res
	no = False
	for u in range(26):
		if len(adj[u]) > 0 and (not visit[u]):
			no = True
	if no:
		print('NO')
		continue
	for i in range(26):
		if not visit[i]:
			ans.append(i)
	print('YES')
	for i in ans:
		print(chr(i + ord('a')), end='')
	print()


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	s = input().strip()
	LEN = len(s)
	Group = [i for i in range(26)]
	Nodes = [1] * 26

	def find(x):
		while Group[x] != x:
			x = Group[x]
		return x

	def Union(x, y):
		if find(x) != find(y):
			if Nodes[find(x)] < Nodes[find(y)]:
				Nodes[find(y)] += Nodes[find(x)]
				Nodes[find(x)] = 0
				Group[find(x)] = find(y)
			else:
				Nodes[find(x)] += Nodes[find(y)]
				Nodes[find(y)] = 0
				Group[find(y)] = find(x)
	ADJ = [set() for i in range(26)]
	for i in range(1, LEN):
		x = ord(s[i - 1]) - 97
		y = ord(s[i]) - 97
		ADJ[x].add(y)
		ADJ[y].add(x)
		Union(x, y)
	Gr = [find(i) for i in range(26)]
	USEGR = [[] for i in range(26)]
	for i in range(26):
		USEGR[Gr[i]].append(i)
	noflag = 0
	ANS = []
	for i in range(26):
		if len(USEGR[i]) == 1:
			ANS.append(USEGR[i][0])
			continue
		elif len(USEGR[i]) == 0:
			continue
		X = USEGR[i]
		MAX = -1
		MIN = 30
		for x in X:
			MAX = max(MAX, len(ADJ[x]))
			MIN = min(MIN, len(ADJ[x]))
		if MAX > 2 or MIN >= 2:
			noflag = 1
			break
		for x in X:
			if len(ADJ[x]) == 1:
				Q = [x]
				break
		ANS1 = []
		USE = [0] * 26
		USE[x] = 1
		while Q:
			x = Q.pop()
			ANS1.append(x)
			for to in ADJ[x]:
				if USE[to] == 0:
					USE[to] = 1
					Q.append(to)
		ANS.extend(ANS1)
	if noflag:
		print('NO')
		continue
	print('YES')
	print(''.join([chr(a + 97) for a in ANS]))


for _ in range(int(input())):
	s = list(input())
	current = 0
	ans = [s[0]]
	dir = 1
	flag = False
	for i in range(1, len(s)):
		if s[i] not in ans:
			if dir == 1 and current == len(ans) - 1:
				ans.append(s[i])
				current += 1
			elif dir == -1 and current == 0:
				ans.insert(0, s[i])
			else:
				print('NO')
				flag = True
				break
		elif current < len(ans) - 1 and ans[current + 1] == s[i]:
			dir = 1
			current += 1
			continue
		elif current > 0 and ans[current - 1] == s[i]:
			dir = -1
			current -= 1
			continue
		else:
			print('NO')
			flag = True
			break
	if not flag:
		print('YES')
		print(''.join(ans), end='')
		for e in range(26):
			if chr(e + 97) not in ans:
				print(chr(e + 97), end='')
		print()


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')
from collections import defaultdict

def dfs(x, y):
	global ans, d, adj, l
	d[x] = 1
	l.append(x)
	for i in adj[x]:
		if not d[i]:
			dfs(i, x)
		elif i != y:
			ans = False
t = int(input())
for i in range(t):
	s = input()
	adj = defaultdict(list)
	d = defaultdict(int)
	l1 = [[0 for j in range(26)] for p in range(26)]
	l2 = []
	for j in range(97, 123):
		l2.append(chr(j))
	ans = True
	if s.count(s[0]) == len(s):
		print('YES')
		print(''.join(l2))
	else:
		l = []
		x = ''
		for j in range(len(s) - 1):
			if s[j] != s[j + 1]:
				if l1[ord(s[j]) - 97][ord(s[j + 1]) - 97] == 0:
					adj[s[j]].append(s[j + 1])
					adj[s[j + 1]].append(s[j])
					l1[ord(s[j]) - 97][ord(s[j + 1]) - 97] = 1
					l1[ord(s[j + 1]) - 97][ord(s[j]) - 97] = 1
					if len(adj[s[j]]) > 2:
						ans = False
						break
		for j in adj:
			if len(adj[j]) == 1:
				x = j
		if ans == False or x == '':
			print('NO')
		else:
			dfs(x, -1)
			s1 = ''.join(l)
			for j in l2:
				if j not in s1:
					s1 += j
			if ans == True:
				print('YES')
				print(s1)
			else:
				print('NO')


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from functools import *
from itertools import permutations, combinations, groupby
import sys
import bisect
import string
import math
import time
import random

def Golf():
	(*a,) = map(int, open(0))

def S_():
	return input()

def IS():
	return input().split()

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

def I():
	return int(input())

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

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

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			g[a].append(bb)
			if not Directed:
				g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}):
	mp = [1] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [1] + [mp_def[j] for j in s] + [1]
	mp += [1] * (w + 2)
	return (h + 2, w + 2, mp, found)

def bit_combination(k, n=2):
	rt = []
	for tb in range(n ** k):
		s = [tb // n ** bt % n for bt in range(k)]
		rt += [s]
	return rt

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
input = lambda : sys.stdin.readline().rstrip()

def ran_input():
	import random
	n = random.randint(4, 16)
	(rmin, rmax) = (1, 10)
	a = [random.randint(rmin, rmax) for _ in range(n)]
	return (n, a)
show_flg = False
show_flg = True
ans = 0
t = I()
for _ in range(t):
	ans = 0
	s = StoI()
	n = len(s)
	m = [set() for i in range(26)]
	g = [[] for i in range(26)]
	for i in range(n - 1):
		m[s[i]].add(s[i + 1])
		m[s[i + 1]].add(s[i])
	g = [(i, len(m[i])) for i in range(26)]
	g.sort(key=lambda x: x[1])
	used = [False] * 26
	ans = ''
	for (i, li) in g:
		if used[i]:
			continue
		if li >= 2:
			ans = 'NO'
			break
		q = [i]
		tmp = ''
		while q:
			c = q.pop()
			used[c] = True
			ch = ItoS(c)
			if ch in tmp:
				ans = 'NO'
				break
			tmp += ch
			if len(m[c]) > 2:
				ans = 'NO'
				break
			for nb in m[c]:
				if not used[nb]:
					q.append(nb)
					used[nb] = True
		if ans == 'NO':
			break
		ans += tmp
	if ans != 'NO':
		print('YES')
	print(ans)


import sys

def goback(ins, idx, ss, cur, chk):
	if idx == len(ins):
		return ss
	if chk[ord(ins[idx]) - ord('a')] == 1:
		if cur + 1 < len(ss) and ss[cur + 1] == ins[idx]:
			re = goback(ins, idx + 1, ss, cur + 1, chk)
			if re is not None:
				return re
		elif cur - 1 >= 0 and ss[cur - 1] == ins[idx]:
			re = goback(ins, idx + 1, ss, cur - 1, chk)
			if re is not None:
				return re
	else:
		chk[ord(ins[idx]) - ord('a')] = 1
		if cur == 0:
			re = goback(ins, idx + 1, ins[idx] + ss, cur, chk)
			if re is not None:
				return re
		elif cur == len(ss) - 1:
			re = goback(ins, idx + 1, ss + ins[idx], cur + 1, chk)
			if re is not None:
				return re
		chk[ord(ins[idx]) - ord('a')] = 0
	return None
for _ in range(int(sys.stdin.readline().rstrip())):
	s = sys.stdin.readline().rstrip()
	check = [0] * 26
	check[ord(s[0]) - ord('a')] = 1
	result = goback(s, 1, s[0], 0, check)
	if result is None:
		print('NO')
	else:
		for (ix, i) in enumerate(check):
			if i == 0:
				result += chr(ix + ord('a'))
		print(f'YES\n{result}')


import sys
import string
t = int(input())
letters = string.ascii_lowercase
for _ in range(t):
	s = input()
	d = {}
	for c in letters:
		d[c] = []
	for i in range(len(s) - 1):
		d[s[i]].append(s[i + 1])
		d[s[i + 1]].append(s[i])
	num_1 = 0
	num_3 = 0
	for c in letters:
		d[c] = list(set(d[c]))
		if len(d[c]) > 2:
			num_3 += 1
		elif len(d[c]) == 1:
			num_1 += 1
	if (num_3 > 0 or num_1 == 0) and len(s) > 1:
		print('NO')
		continue
	result = ''
	for c in letters:
		if len(d[c]) == 0:
			result = c + result

	def dfs(x):
		global result
		result = x + result
		nxt = d[x]
		for c in nxt:
			if not c in result:
				dfs(c)
	for c in letters:
		if len(d[c]) == 1:
			dfs(c)
			break
	print('YES')
	print(result)


t = int(input())
chars = ['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']
for _ in range(t):
	s = input()
	a = [0] * 200
	a[100] = s[0]
	i = 100
	can = True
	missing = set(chars)
	missing.discard(s[0])
	for c in s[1:]:
		if c in missing:
			missing.remove(c)
			if a[i + 1] == 0:
				a[i + 1] = c
				i += 1
			elif a[i - 1] == 0:
				a[i - 1] = c
				i -= 1
			else:
				can = False
				break
		elif a[i - 1] == c or a[i + 1] == c:
			if a[i - 1] == c:
				i -= 1
			else:
				i += 1
			continue
		else:
			can = False
			break
	if can:
		print('YES')
		for i in a:
			if i != 0:
				print(i, end='')
		for i in missing:
			print(i, end='')
		print()
	else:
		print('NO')


def solve():
	s = input()
	ans = s[0]
	for i in range(1, len(s)):
		if s[i] not in ans:
			ind = ans.index(s[i - 1])
			if ind == len(ans) - 1:
				ans += s[i]
			elif ind == 0:
				ans = s[i] + ans
			else:
				print('NO')
				return
		else:
			ind = ans.index(s[i])
			if ind != 0 and ind != len(ans) - 1:
				if s[i - 1] != ans[ind - 1] and s[i - 1] != ans[ind + 1]:
					print('NO')
					return
			elif ind == 0 and s[i - 1] != ans[ind + 1]:
				print('NO')
				return
			elif ind == len(ans) - 1 and s[i - 1] != ans[ind - 1]:
				print('NO')
				return
	for i in 'abcdefghijklmnopqrstuvwxyz':
		if i not in ans:
			ans += i
	print('YES')
	print(ans, end='\n')
t = int(input())
while t:
	solve()
	t -= 1


from string import ascii_lowercase

def solve(tok: str):
	if len(tok) == 1:
		return ascii_lowercase
	base = tok[0]
	for i in range(len(tok) - 1):
		if tok[i + 1] in base:
			if abs(base.index(tok[i]) - base.index(tok[i + 1])) > 1:
				return None
		elif base.index(tok[i]) == 0:
			base = tok[i + 1] + base
		elif base.index(tok[i]) == len(base) - 1:
			base += tok[i + 1]
		else:
			return None
	base += ''.join((e for e in ascii_lowercase if e not in base))
	return base
for _ in range(int(input())):
	s = input()
	res = solve(s)
	if res:
		print('YES\n{}'.format(res))
	else:
		print('NO')


tc = int(input())
while tc:
	tc -= 1
	s = input().strip()
	adj = [[] for i in range(27)]
	for ind in range(1, len(s)):
		adj[ord(s[ind]) - ord('a')].append(ord(s[ind - 1]) - ord('a'))
		adj[ord(s[ind - 1]) - ord('a')].append(ord(s[ind]) - ord('a'))
	flag = 0
	for i in range(26):
		adj[i] = list(set(adj[i]))
		if len(adj[i]) > 2:
			print('NO')
			flag = 1
			break
	if flag:
		continue
	res = []
	fl = [0] * 27
	for i in range(26):
		if not fl[i] and len(adj[i]) < 2:
			st = i
			while not fl[st]:
				fl[st] = 1
				res.append(st)
				for j in range(len(adj[st])):
					if not fl[adj[st][j]]:
						st = adj[st][j]
						break
	if len(res) != 26:
		print('NO')
	else:
		print('YES')
		ans = ''
		for i in range(26):
			ch = res[i] + ord('a')
			ans += chr(ch)
		print(ans)


from collections import defaultdict
for _ in range(int(input())):
	s = input()
	n = len(s)
	g = defaultdict(list)
	x = [0] * 26
	for i in range(n - 1):
		if i == 0:
			if s[1] not in g[s[i]]:
				g[s[i]].append(s[1])
				x[ord(s[i]) - ord('a')] += 1
		else:
			if s[i - 1] not in g[s[i]]:
				g[s[i]].append(s[i - 1])
				x[ord(s[i]) - ord('a')] += 1
			if s[i + 1] not in g[s[i]]:
				g[s[i]].append(s[i + 1])
				x[ord(s[i]) - ord('a')] += 1
	if n > 1:
		if s[-2] not in g[s[-1]]:
			g[s[-1]].append(s[-2])
			x[ord(s[-1]) - ord('a')] += 1
	if n == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
	elif x.count(1) == 0:
		print('NO')
	elif x.count(1) + x.count(2) + x.count(0) != 26:
		print('NO')
	else:
		print('YES')
		for i in range(26):
			if x[i] == 1:
				break
		start = chr(i + ord('a'))
		f = [0] * 26
		p = []
		p.append(start)
		f[ord(start) - ord('a')] = 1
		c = 1
		while c > 0:
			start = p.pop()
			c -= 1
			print(start, end='')
			for j in g[start]:
				if f[ord(j) - ord('a')] == 0:
					p.append(j)
					f[ord(j) - ord('a')] = 1
					c += 1
		for i in range(26):
			if f[i] == 0:
				print(chr(i + ord('a')), end='')
		print()


def f():
	alphabet = set('abcdefghijklmnopqrstuvwxyz')
	st = input()
	ans = {}
	if len(st) == 1:
		return list(alphabet)
	pr_ans = []
	for i in range(len(st) - 1):
		if st[i] not in ans:
			ans[st[i]] = set(st[i + 1])
		else:
			ans[st[i]].add(st[i + 1])
			if len(ans[st[i]]) == 3:
				return None
		if st[i + 1] not in ans:
			ans[st[i + 1]] = set(st[i])
		else:
			ans[st[i + 1]].add(st[i])
			if len(ans[st[i + 1]]) == 3:
				return None
	if all(map(lambda x: len(x) == 2, ans.values())):
		return None
	else:
		first_last = []
		answer = []
		for (k, v) in ans.items():
			if len(v) == 1:
				first_last.append(k)
		answer.append(first_last[0])
		alphabet -= set(first_last[0])
		curr = ans[first_last[0]].pop()
		while curr != first_last[1]:
			answer.append(curr)
			alphabet -= set(curr)
			a = ans[curr].pop()
			b = ans[curr].pop()
			if a in alphabet:
				curr = a
			else:
				curr = b
		answer.append(first_last[1])
		alphabet -= set(first_last[1])
		return answer + list(alphabet)
s = int(input())
for i in range(s):
	t = f()
	if t == None:
		print('NO')
	else:
		print('YES')
		print(''.join(t))


import math
t = int(input())
while t:
	s = input()
	f1 = True
	a = ''
	for i in range(len(s)):
		if i == 0:
			a += s[i]
		elif s[i] not in a:
			if f1:
				a += s[i]
			else:
				a = s[i] + a
		elif a.index(s[i]) == 0:
			f1 = False
		else:
			f1 = True
	for i in range(26):
		if chr(97 + i) not in a:
			a += chr(97 + i)
	j = a.index(s[0])
	flag = True
	for i in range(1, len(s)):
		index = a.index(s[i])
		if index - j == 1 or j - index == 1:
			j = index
		else:
			flag = False
			break
	if flag == False:
		print('NO')
	else:
		print('YES')
		print(a)
	t -= 1


for _ in range(int(input())):
	s = input()
	l = []
	l.append(s[0])
	f = 0
	m = 0
	j = 0
	for i in range(1, len(s)):
		if s[i] in l:
			if l[j] == s[i]:
				f = 1
				break
			if j > 0 and j < m and (l[j - 1] != s[i]) and (l[j + 1] != s[i]):
				f = 1
				break
			if j == 0 and l[j + 1] != s[i]:
				f = 1
				break
			if j == m and l[j - 1] != s[i]:
				f = 1
				break
		if l[j] == s[i]:
			f = 1
			break
		if j > 0 and j < m and (l[j - 1] != s[i]) and (l[j + 1] != s[i]):
			f = 1
			break
		if j > 0 and l[j - 1] == s[i]:
			j -= 1
			continue
		if j < m and l[j + 1] == s[i]:
			j += 1
			continue
		if j == 0 and m == 0:
			j += 1
			m += 1
			l.append(s[i])
		elif j == 0 and m > 0:
			m += 1
			l.insert(0, s[i])
		elif j == m:
			j += 1
			m += 1
			l.append(s[i])
	if f == 1:
		print('NO')
	else:
		print('YES')
		a = []
		for k in range(26):
			a.append(-1)
		for k in l:
			a[ord(k) - 97] = 1
		for k in range(26):
			if a[k] == 1:
				pass
			else:
				l.append(chr(k + 97))
		str1 = ''
		for i in l:
			str1 += i
		print(str1)


MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
let = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(ii()):
	s = si()
	n = len(s)
	if n < 3:
		print('YES')
		print(s, end='')
		for i in let:
			if not i in s:
				print(i, end='')
		print()
	else:
		fg = 0
		l = [s[0], s[1]]
		for i in range(2, n):
			if not s[i] in l and s[i - 1] == l[0]:
				l.insert(0, s[i])
			elif not s[i] in l and s[i - 1] == l[-1]:
				l.append(s[i])
			elif s[i] in l:
				x = l.index(s[i])
				y = l.index(s[i - 1])
				if abs(x - y) != 1:
					fg = 1
					break
			else:
				fg = 1
				break
		if fg == 0:
			print('YES')
			print(''.join(l), end='')
			for i in let:
				if not i in l:
					print(i, end='')
			print()
		else:
			print('NO')


alphabet = ''.join(sorted('qwertyuiopasdfghjklzxcvbnm'))
for _ in range(int(input())):
	s = input()
	n = len(s)
	chosen = {}
	for c in alphabet:
		chosen[c] = False
	if n == 1:
		print('YES')
		print(alphabet)
	else:
		ans = 'YES'
		keyboard = s[0] + s[1]
		chosen[s[0]] = True
		chosen[s[1]] = True
		j = 1
		for i in range(2, n):
			if j == 0:
				if not chosen[s[i]]:
					keyboard = s[i] + keyboard
					chosen[s[i]] = True
				elif keyboard[j + 1] == s[i]:
					j += 1
				else:
					ans = 'NO'
					break
			elif j == len(keyboard) - 1:
				if not chosen[s[i]]:
					keyboard += s[i]
					j += 1
					chosen[s[i]] = True
				elif keyboard[j - 1] == s[i]:
					j -= 1
				else:
					ans = 'NO'
					break
			elif keyboard[j - 1] == s[i]:
				j -= 1
			elif keyboard[j + 1] == s[i]:
				j += 1
			else:
				ans = 'NO'
				break
		print(ans)
		if ans == 'YES':
			for c in alphabet:
				if not chosen[c]:
					keyboard += c
			print(keyboard)


from sys import stdin

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

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

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	s = input()
	layout = s[:2]
	i = 2
	pnt = 1
	while i < len(s):
		if s[i] not in layout:
			if pnt == 0:
				layout = s[i] + layout
			elif pnt == len(layout) - 1:
				layout += s[i]
				pnt += 1
			else:
				print('NO')
				break
		elif pnt > 0 and layout[pnt - 1] == s[i]:
			pnt -= 1
		elif pnt < len(layout) - 1 and layout[pnt + 1] == s[i]:
			pnt += 1
		else:
			print('NO')
			break
		i += 1
	else:
		for i in range(97, 123):
			if chr(i) not in layout:
				layout += chr(i)
		print('YES')
		print(layout)


from sys import stdin, stdout
import math
d = {}
invd = {}
t = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(t)):
	d[t[i]] = i
	invd[i] = t[i]
t1 = int(stdin.readline().strip())
for _ in range(t1):
	s = stdin.readline().strip()
	d = {}
	for i in range(len(s) - 1):
		if s[i] in d:
			if s[i + 1] not in d[s[i]]:
				d[s[i]].append(s[i + 1])
		else:
			d[s[i]] = [s[i + 1]]
		if s[i + 1] in d:
			if s[i] not in d[s[i + 1]]:
				d[s[i + 1]].append(s[i])
		else:
			d[s[i + 1]] = [s[i]]
	c1 = 0
	c2 = 0
	cg = 0
	for i in d:
		if len(d[i]) == 1:
			c1 += 1
		elif len(d[i]) == 2:
			c2 += 1
		else:
			cg += 1
	if len(s) == 1:
		stdout.write('YES\n' + t + '\n')
	elif c1 == 2 and cg == 0:
		sv = ''
		for i in d:
			if len(d[i]) == 1:
				sv = i
				break
		ans = ''
		s = []
		s.append((sv, ''))
		while len(s) > 0:
			(curr, par) = s.pop(-1)
			ans += curr
			for j in d[curr]:
				if j != par:
					s.append((j, curr))
		for i in t:
			if i not in ans:
				ans += i
		stdout.write('YES\n' + ans + '\n')
	else:
		stdout.write('NO\n')


import math, sys
from collections import defaultdict, deque
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

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

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

def Sn():
	return sys.stdin.readline().strip()
import string

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def end(d, st):
	high = [-1] * 27
	q = deque([st])
	high[ord(st) - 96] = 0
	(ele, mx) = (st, 0)
	while q:
		node = q.popleft()
		for x in d[node]:
			if high[ord(x) - 96] == -1:
				high[ord(x) - 96] = high[ord(node) - 96] + 1
				if high[ord(x) - 96] > mx:
					mx = high[ord(x) - 96]
					ele = x
				q.appendleft(x)
	return ele

def main():
	try:
		s = Sn()
		n = len(s)
		d = defaultdict(set)
		ans = set(string.ascii_lowercase)
		parent = {}
		for x in ans:
			parent[x] = -1
		if n == 1:
			ans.remove(s[0])
			yes()
			print(s + ''.join(list(ans)))
			return
		elif n == 2:
			ans.remove(s[0])
			ans.remove(s[1])
			yes()
			print(s + ''.join(list(ans)))
			return
		ok = True
		d[s[0]].add(s[1])
		d[s[-1]].add(s[-2])
		for i in range(1, n - 1):
			d[s[i]].add(s[i - 1])
			d[s[i]].add(s[i + 1])
			if len(d[s[i]]) > 2:
				ok = False
		if not ok:
			no()
			return
		an = []
		start = end(d, s[0])
		q = deque(start)
		parent[start] = start
		while q:
			node = q.popleft()
			if node not in ans:
				continue
			an.append(node)
			ans.remove(node)
			for x in d[node]:
				if x in ans:
					q.appendleft(x)
					parent[x] = node
				elif parent[node] != x:
					ok = False
					break
		if ok:
			yes()
			an = ''.join(an)
			ans = list(ans)
			ans.sort()
			for x in ans:
				an += x
			print(an)
		else:
			no()
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


def dfs(listed, start, visited, result):
	visited.add(start)
	result.append(chr(start + ord('a')))
	for i in listed[start]:
		if i not in visited:
			dfs(listed, i, visited, result)

def keyboard(string):
	adj_list = [set() for i in range(26)]
	if len(string) == 1:
		return 'YES\n' + ''.join([chr(i + ord('a')) for i in range(len(adj_list)) if len(adj_list[i]) == 0])
	for i in range(len(string) - 1):
		index1 = ord(string[i]) - ord('a')
		index2 = ord(string[i + 1]) - ord('a')
		if len(adj_list[index1]) == 2 and ord(string[i + 1]) - ord('a') not in adj_list[index1]:
			return 'NO'
		adj_list[index1].add(ord(string[i + 1]) - ord('a'))
		if len(adj_list[index2]) == 2 and ord(string[i]) - ord('a') not in adj_list[index2]:
			return 'NO'
		adj_list[index2].add(ord(string[i]) - ord('a'))
	start_index = -1
	for i in range(len(adj_list)):
		if len(adj_list[i]) == 1:
			start_index = i
			break
	if start_index == -1:
		return 'NO'
	result = []
	dfs(adj_list, start_index, set(), result)
	return 'YES\n' + ''.join(result + [chr(i + ord('a')) for i in range(len(adj_list)) if len(adj_list[i]) == 0])
useless = int(input())
for i in range(useless):
	string = input()
	print(keyboard(string))


s = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(int(input())):
	a = input()
	n = False
	ans = []
	for i in range(len(a)):
		if a[i] not in ans:
			if i == 0:
				ans.append(a[i])
			else:
				ind = ans.index(a[i - 1])
				if ind == 0 or ind == len(ans) - 1:
					if ind == 0:
						ans.insert(0, a[i])
					else:
						ans.append(a[i])
				else:
					print('NO')
					n = True
					break
		else:
			pi = ans.index(a[i - 1])
			ci = ans.index(a[i])
			if abs(pi - ci) != 1:
				print('NO')
				n = True
				break
	for chr in s:
		if chr not in ans:
			ans.append(chr)
	if n is False:
		print('YES')
		print(*ans, sep='')


def solve(S):
	layout = {}
	pos = 0
	layout[pos] = S[0]
	seen = set()
	seen.add(S[0])
	for ch in S[1:]:
		if pos + 1 in layout and layout[pos + 1] == ch:
			pos += 1
		elif pos - 1 in layout and layout[pos - 1] == ch:
			pos -= 1
		else:
			if ch in seen:
				return 'NO'
			seen.add(ch)
			if pos + 1 not in layout:
				pos += 1
				layout[pos] = ch
			elif pos - 1 not in layout:
				pos -= 1
				layout[pos] = ch
			else:
				return 'NO'
	layout = [v for (k, v) in sorted(layout.items())]
	layout.extend(set('abcdefghijklmnopqrstuvwxyz') - set(layout))
	assert len(layout) == 26
	return 'YES' + '\n' + ''.join(layout)
(T,) = map(int, input().split())
for t in range(T):
	S = input()
	ans = solve(S)
	print(ans)


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
from string import ascii_lowercase as al
for _ in range(int(input())):
	s = input()
	if len(s) == 1:
		print('YES')
		print(al)
		continue
	adj = {x: set() for x in al}
	possible = True
	unused = set(al)
	for (i, c) in enumerate(s[:-1]):
		adj[c].add(s[i + 1])
		adj[s[i + 1]].add(c)
		if c in unused:
			unused.remove(c)
		if s[i + 1] in unused:
			unused.remove(s[i + 1])
	impossible = False
	out = []
	for c in adj:
		l = list(adj[c])
		if len(l) > 2:
			impossible = True
		elif len(l) == 1:
			out.append(c)
	if len(out) != 2:
		impossible = True
	if not impossible:
		print('YES')
		end = out.pop()
		used = set(al) - unused
		used.remove(out[0])
		while used:
			n = adj[out[-1]].pop()
			if n in out:
				continue
			out.append(n)
			if n in used:
				used.remove(n)
		out = ''.join(out) + ''.join(unused)
		print(out)
	else:
		print('NO')


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
for _ in range(int(input())):
	ans = deque()
	s = input()
	ans.append(s[0])
	a = 0
	flag = 'YES'
	for i in range(1, len(s)):
		if a == 0:
			if len(ans) > 1:
				if ans[a + 1] == s[i]:
					a += 1
				else:
					ans.appendleft(s[i])
			else:
				ans.append(s[i])
				a += 1
		elif a == len(ans) - 1:
			if ans[a - 1] == s[i]:
				a -= 1
			else:
				ans.append(s[i])
				a += 1
		elif ans[a - 1] == s[i]:
			a -= 1
		elif ans[a + 1] == s[i]:
			a += 1
		else:
			flag = 'NO'
			break
	for i in range(97, 123):
		if chr(i) not in ans:
			ans.append(chr(i))
	if len(ans) != 26:
		flag = 'NO'
	print(flag)
	if flag == 'YES':
		print(''.join(ans))


t = int(input())
for _______ in range(t):
	s = input()
	alphabet = 'qwertyuioplkjhgfdsazxcvbnm'
	if len(s) > 1:
		was = set()
		kk = ''
		E = {alphabet[i]: set() for i in range(len(alphabet))}
		for i in range(len(s) - 1):
			E[s[i]].add(s[i + 1])
			E[s[i + 1]].add(s[i])
		f = 1
		for el in E:
			if len(E[el]) > 2:
				f = 2
		for el in E:
			if len(E[el]) == 1 and f != 2:
				kk += el
				was.add(el)
				now = el
				while len(E[now]):
					for el in E[now]:
						kk += el
						was.add(el)
						E[el].remove(now)
						now = el
				f = 0
				break
		if not kk or f:
			print('NO')
		else:
			for el in alphabet:
				if el not in was:
					kk += el
			print('YES')
			print(kk)
	else:
		print('YES')
		print(alphabet)


from collections import Counter
from collections import defaultdict
import math
t = int(input())
for i in range(0, t):
	s = input()
	s = list(s)
	a = [0] * 1000
	d = defaultdict(lambda : 0)
	k = 50
	a[k] = s[0]
	d[s[0]] = 1
	f = 1
	for i in range(1, len(s)):
		if a[k + 1] == s[i]:
			k = k + 1
			continue
		elif a[k - 1] == s[i]:
			k = k - 1
			continue
		elif a[k + 1] == 0 and d[s[i]] == 0:
			k = k + 1
			a[k] = s[i]
			d[s[i]] = 1
		elif a[k - 1] == 0 and d[s[i]] == 0:
			k = k - 1
			a[k] = s[i]
			d[s[i]] = 1
		else:
			f = 0
			break
	if f == 0:
		print('NO')
	else:
		s1 = ''
		for i in range(0, 200):
			if a[i] != 0:
				s1 = s1 + a[i]
		s2 = ''
		for i in range(97, 123):
			s2 = s2 + chr(i)
		s3 = list(s1)
		s4 = list(s2)
		s5 = list(set(s4) - set(s3))
		s5 = ''.join(s5)
		print('YES')
		print(s1 + s5)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from queue import PriorityQueue
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()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations

def dfs(n):
	boo[n] = True
	st.append(n)
	for i in hash[n]:
		if not boo[i]:
			dfs(i)

def find_parent(u):
	if par[u] != u:
		par[u] = find_parent(par[u])
	return par[u]
n = int(input())
for i in range(n):
	s = list(input())
	hash = defaultdict(set)
	edg = set()
	flag = 0
	for i in range(len(s) - 1):
		hash[ord(s[i]) - 97].add(ord(s[i + 1]) - 97)
		hash[ord(s[i + 1]) - 97].add(ord(s[i]) - 97)
		(a, b) = (max((ord(s[i]) - 97, ord(s[i + 1]) - 97)), min((ord(s[i]) - 97, ord(s[i + 1]) - 97)))
		edg.add((a, b))
		if len(hash[ord(s[i]) - 97]) > 2 or len(hash[ord(s[i]) - 97]) > 2:
			flag = 1
			break
	par = [i for i in range(26)]
	for (a, b) in edg:
		(z1, z2) = (find_parent(a), find_parent(b))
		if z1 != z2:
			par[z1] = z2
		else:
			flag = 1
			break
	no = []
	ans = []
	ba = []
	if not flag:
		print('YES')
		boo = [False] * 26
		for i in range(26):
			if not boo[i] and len(hash[i]) == 1:
				st = []
				dfs(i)
				ba.append(st)
			if not boo[i] and len(hash[i]) == 0:
				no.append(i)
		for i in ba:
			ans += i
			if no != []:
				z = no.pop()
				ans += [z]
		ans += no
		for i in range(26):
			ans[i] = chr(ans[i] + 97)
		print(''.join(ans))
	else:
		print('NO')


import string

def main(s):
	layout = s[0]
	pos = 0
	for i in s[1:]:
		n = len(layout)
		if i in layout:
			if layout[max(0, pos - 1)] == i:
				pos -= 1
			elif layout[min(pos + 1, n - 1)] == i:
				pos += 1
			else:
				return ['NO']
		elif i not in layout:
			if pos + 1 > n - 1:
				layout = layout + i
				pos += 1
			elif pos - 1 < 0:
				layout = i + layout
			else:
				return ['NO']
	for i in string.ascii_lowercase:
		if i not in layout:
			layout = layout + i
	return ['YES', layout]
t = int(input())
for _ in range(t):
	s = input()
	ans = main(s)
	[print(i) for i in ans]


t = int(input())
for _ in range(t):
	s = input()
	if len(s) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	l = []
	for i in range(26):
		l.append([])
	for i in range(len(s)):
		x = ord(s[i]) - 97
		if i == 0:
			l[x].append(s[i + 1])
		elif i == len(s) - 1:
			l[x].append(s[i - 1])
		else:
			l[x].append(s[i + 1])
			l[x].append(s[i - 1])
	flag = 0
	for i in range(len(l)):
		l[i] = list(set(l[i]))
	for i in range(len(l)):
		if len(l[i]) > 2:
			print('NO')
			flag = 1
			break
	if flag == 1:
		continue
	newflag = 0
	ans = ''
	for i in range(26):
		s = ''
		if chr(i + 97) in ans or len(l[i]) == 0:
			continue
		if len(l[i]) == 2:
			s += l[i][0]
			s += chr(i + 97)
			s += l[i][1]
		elif len(l[i]) == 1:
			s += l[i][0]
			s += chr(i + 97)
		while True:
			x = ord(s[0]) - 97
			y = ord(s[len(s) - 1]) - 97
			change = 0
			for p in l[x]:
				if p not in s and p not in ans:
					s = p + s
					change += 1
					break
				elif s[1] != p:
					newflag = 1
					break
			for q in l[y]:
				if q not in s and q not in ans:
					s = s + q
					change += 1
					break
				elif s[len(s) - 2] != q:
					newflag = 1
					break
			if change == 0:
				break
		ans += s
	for i in range(26):
		if len(l[i]) == 0:
			ans += chr(i + 97)
	if newflag == 1:
		print('NO')
	else:
		print('YES')
		print(ans)


class graph:

	def __init__(self, gdict=None):
		if gdict is None:
			gdict = defaultdict(list)
		(self.gdict, self.edges) = (gdict, defaultdict(int))

	def get_vertices(self):
		return list(self.gdict.keys())

	def add_edge(self, node1, node2):
		self.gdict[node1].append(node2)
		self.gdict[node2].append(node1)
		self.edges[node1, node2] = 1

	def dfsUtil(self, v):
		(stack, self.visit, ans) = ([v], defaultdict(int), deque([]))
		while stack:
			s = stack.pop()
			if not self.visit[s]:
				ans.append(s)
				self.visit[s] = 1
			for i in self.gdict[s]:
				if not self.visit[i]:
					stack.append(i)
		return ans
from collections import *
for i in range(int(input())):
	(s, g, be) = (input(), graph(), [])
	for j in range(1, len(s)):
		if not g.edges[s[j], s[j - 1]] and (not g.edges[s[j - 1], s[j]]):
			g.add_edge(s[j], s[j - 1])
	for (j, k) in g.gdict.items():
		if len(k) == 1:
			be.append(j)
	if len(be) != 2 and len(s) > 1:
		print('NO')
	else:
		print('YES')
		ans = deque(s)
		if be:
			ans = g.dfsUtil(be[0])
		mem = Counter(ans)
		for j in range(ord('a'), ord('z') + 1):
			if not mem[chr(j)]:
				ans.append(chr(j))
		print(''.join(ans))


t = int(input())
for _ in range(t):
	s = [i for i in input()]
	bckt = ['' for i in range(55)]
	pos = 27
	ok = True
	bckt[pos] = s[0]
	for i in range(1, len(s)):
		if bckt[pos] == s[i]:
			continue
		elif bckt[pos - 1] == s[i]:
			pos -= 1
		elif bckt[pos + 1] == s[i]:
			pos += 1
		elif bckt[pos + 1] == '':
			pos += 1
			bckt[pos] = s[i]
		elif bckt[pos - 1] == '':
			pos -= 1
			bckt[pos] = s[i]
		else:
			ok = False
			break
	if ok:
		s = ''.join(bckt) + ''.join([chr(97 + i) for i in range(26) if chr(97 + i) not in bckt])
		if len(s) == 26:
			print('YES')
			print(s)
		else:
			print('NO')
	else:
		print('NO')


def dfs(n, matr):
	global res
	global vis
	global tt
	res = res + chr(ord('a') + n)
	cnt = 0
	for i in range(26):
		if matr[n][i] == 1 and vis[i] == 0:
			vis[i] = 1
			if cnt > 0:
				tt = 0
				return
			cnt += 1
			dfs(i, matr)
t = int(input())
matr = [[0] * 26 for i in range(26)]
vis = [0] * 26
for q in range(t):
	f = ord('a')
	s = input()
	prev = ord(s[0]) - f
	res = ''
	for i in s[1:]:
		n = ord(i) - f
		matr[n][prev] = 1
		matr[prev][n] = 1
		prev = n
	tt = 0
	for i in range(26):
		cnt = 0
		for j in range(26):
			cnt += matr[i][j]
		if cnt > 2:
			tt = 0
			break
		if cnt == 1:
			tt = 1
			buf = i
	if tt:
		vis[buf] = 1
		dfs(buf, matr)
	if len(s) == 1:
		tt = 1
	if tt == 0:
		print('NO')
	else:
		print('YES')
		for j in range(26):
			if not vis[j]:
				res = res + chr(ord('a') + j)
		print(res)
	for i in range(26):
		vis[i] = 0
		for j in range(26):
			matr[i][j] = 0


def make_keyboard(string):
	index = 0
	result = []
	visited = set()
	for val in string:
		if len(result) == 0:
			result.append(val)
			visited.add(val)
			continue
		if val not in visited and index == len(result) - 1:
			result.append(val)
			visited.add(val)
			index += 1
		elif val not in visited and index == 0:
			result.insert(0, val)
			visited.add(val)
		elif val not in visited:
			return ('NO', None)
		else:
			left = index - 1
			right = index + 1
			if 0 <= left and result[left] == val:
				index = left
			elif right < len(result) and result[right] == val:
				index = right
			else:
				return ('NO', None)
	for i in range(26):
		lt = chr(ord('a') + i)
		if lt not in visited:
			result.append(lt)
	return ('YES', ''.join(result))

def solution(inp1):
	return make_keyboard(inp1)

def main():
	inp1 = input()
	length = int(inp1)
	for i in range(length):
		inp1 = input()
		result = solution(inp1)
		print(result[0])
		if result[1]:
			print(result[1])
main()


def solution():
	from sys import stdin, stdout
	(_input, _print, _range, _int, _set, _len) = (stdin.readline, stdout.write, range, int, set, len)
	_abs = abs
	for _ in _range(_int(_input())):
		s = _input().replace('\n', '')
		h = {}
		k = {}
		index = 0
		old_char = s[0]
		h[s[0]] = index
		k[index] = s[0]
		f = True
		for current_char in s[1:]:
			if current_char not in h.keys():
				if index + 1 in k.keys():
					if index - 1 in k.keys():
						f = False
						break
					else:
						index -= 1
				else:
					index += 1
				h[current_char] = index
				k[index] = current_char
			elif _abs(h[old_char] - h[current_char]) > 1:
				f = False
				break
			else:
				index = h[current_char]
			old_char = current_char
		if f:
			_sorted = sorted
			_print('YES\n')
			current_alph = _set('abcdefghijklmnopqrstuvwxyz')
			for i in _sorted(k.keys()):
				_print(k[i])
				current_alph.remove(k[i])
			for i in current_alph:
				_print(i)
			_print('\n')
		else:
			_print('NO\n')
solution()


def calculate(str_val):
	chars = set()
	index = 0
	build = ''
	for i in str_val:
		if i not in chars:
			if index == 0:
				build = i + build
				index = 0
			elif index == len(build) - 1:
				build = build + i
				index = len(build) - 1
			else:
				print('NO')
				return
			chars.add(i)
		elif build[max(0, index - 1)] == i:
			index = max(index - 1, 0)
		elif build[min(len(build) - 1, index + 1)] == i:
			index = min(len(build) - 1, index + 1)
		else:
			print('NO')
			return
	print('YES')
	for i in range(97, 123):
		if chr(i) not in chars:
			build += chr(i)
			chars.add(i)
	print(build)

def runner():
	val = input()
	for i in range(int(val)):
		ans = input()
		calculate(ans)
runner()


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input().strip()
mod = 1000000007

def dfs(d, s, visited):
	visited[s] = 1
	print(s, end='')
	for i in d[s]:
		if i not in visited:
			dfs(d, i, visited)
for i in range(I()):
	s = S()
	d = defaultdict(list)
	f = 0
	for i in range(0, len(s) - 1):
		if s[i + 1] not in d[s[i]]:
			d[s[i]].append(s[i + 1])
		if s[i] not in d[s[i + 1]]:
			d[s[i + 1]].append(s[i])
	visited = defaultdict(int)
	c = 0
	b = []
	for i in d:
		if len(d[i]) > 2:
			f = 1
			break
		if len(d[i]) == 1:
			b.append(i)
	if (f or len(b) != 2) and len(s) != 1:
		print('NO')
		continue
	print('YES')
	if len(s) != 1:
		k = b[0]
		dfs(d, k, visited)
	for i in 'abcdefghijklmnopqrstuvwxyz':
		if i not in d:
			print(i, end='')
	print()


from collections import defaultdict

def dfs(node, arr, seen):
	r = node
	seen[node] = True
	for ch in arr[node]:
		if ch not in seen:
			r += dfs(ch, arr, seen)
	return r

def main():
	t = int(input())
	for _ in range(t):
		s = input()
		n = len(s)
		if n == 1:
			ret = ''.join([chr(ord('a') + i) for i in range(26)])
			print('YES')
			print(ret)
			continue
		arr = defaultdict(list)
		for i in range(n - 1):
			(fst, snd) = (s[i], s[i + 1])
			if snd not in arr[fst]:
				arr[fst].append(snd)
				arr[snd].append(fst)
		(flag, st) = (False, -1)
		for ch in arr:
			if len(arr[ch]) > 2:
				flag = True
				break
			if len(arr[ch]) == 1:
				st = ch
		if flag or st == -1:
			print('NO')
		else:
			print('YES')
			seen = {}
			ret = dfs(st, arr, seen)
			for i in range(26):
				base = ord('a')
				if chr(i + base) not in ret:
					ret += chr(i + base)
			print(ret)
main()


for _ in range(int(input())):
	s = input()
	if len(s) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	ans = ''
	ans += s[:2]
	pos = 1
	le = 2
	dic = {}
	for i in 'abcdefghijklmnopqrstuvwxyz':
		dic[i] = 0
	dic[s[0]] = 1
	dic[s[1]] = 1
	flag = 0
	for i in range(2, len(s)):
		if pos == 0 and ans[pos + 1] == s[i]:
			pos += 1
		elif pos == 0 and dic[s[i]] == 0:
			ans = s[i] + ans
			le += 1
			dic[s[i]] = 1
		elif pos + 1 == le and ans[pos - 1] == s[i]:
			pos -= 1
		elif pos + 1 == le and dic[s[i]] == 0:
			ans += s[i]
			le += 1
			pos += 1
			dic[s[i]] = 1
		elif pos > 0 and ans[pos - 1] == s[i]:
			pos -= 1
		elif pos + 1 < le and ans[pos + 1] == s[i]:
			pos += 1
		else:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')
		print(ans, end='')
		for i in dic:
			if dic[i] == 0:
				print(i, end='')
		print('')


t = int(input())
for i in range(t):
	s = input()
	f = True
	st = set()
	answer = ''
	pos = 0
	n = 0
	for l in s:
		if l not in st:
			st.add(l)
			n += 1
			if pos == n - 1:
				answer = answer + l
				pos += 1
			elif pos == 1:
				answer = l + answer
			else:
				f = False
				break
		else:
			if pos < n:
				if answer[pos] == l:
					pos += 1
					continue
			if pos > 1:
				if answer[pos - 2] == l:
					pos -= 1
					continue
			f = False
			break
	if f:
		print('YES')
		print(answer, end='')
		for l in 'abcdefghijklmnopqrstuvwxyz':
			if l not in st:
				print(l, end='')
		print()
	else:
		print('NO')


for i in range(int(input())):
	password = input()
	answer_exists = True
	keyboard = ''
	current_finger_position = -1
	for j in range(len(password)):
		if current_finger_position == -1:
			current_finger_position = 0
			keyboard = password[j]
		elif password[j] in keyboard:
			if current_finger_position == 0:
				if password[j] != keyboard[current_finger_position + 1]:
					answer_exists = False
				else:
					current_finger_position += 1
			elif current_finger_position == len(keyboard) - 1:
				if password[j] != keyboard[current_finger_position - 1]:
					answer_exists = False
				else:
					current_finger_position -= 1
			elif password[j] != keyboard[current_finger_position + 1] and password[j] != keyboard[current_finger_position - 1]:
				answer_exists = False
			else:
				current_finger_position += 1 if password[j] == keyboard[current_finger_position + 1] else -1
		elif current_finger_position != 0 and current_finger_position != len(keyboard) - 1:
			answer_exists = False
		elif current_finger_position == len(keyboard) - 1:
			keyboard = keyboard + password[j]
			current_finger_position += 1
		else:
			keyboard = password[j] + keyboard
		if not answer_exists:
			break
	remaining = 'abcdefghijklmnopqrstuvwxyz'
	remaining = list(set(remaining) - set(keyboard))
	if not answer_exists:
		print('NO')
	else:
		print('YES')
		print(keyboard, end='')
		[print(___, end='') for ___ in remaining]
		print()


from string import ascii_lowercase as alph
for q in range(int(input())):
	s = input()
	d = {}
	l = len(s)
	if 1 <= l <= 3 or len(set(s)) == 2:
		print('YES')
		line = set(s)
		rest = set(alph) - set(line)
		print(''.join(line) + ''.join(rest))
		continue
	for i in range(l):
		if i == 0:
			d[s[i]] = d.get(s[i], set()) | {s[i + 1]}
		elif i == l - 1:
			d[s[i]] = d.get(s[i], set()) | {s[i - 1]}
		else:
			d[s[i]] = d.get(s[i], set()) | {s[i + 1]}
			d[s[i]] = d.get(s[i], set()) | {s[i - 1]}
	right = True
	onen = []
	for (char, neigh) in d.items():
		if len(neigh) > 2:
			right = False
			break
		if len(neigh) == 1:
			onen.append(char)
	if not right or len(onen) == 0:
		print('NO')
		continue
	used = set()
	line = []
	prev = onen.pop()
	line.append(prev)
	used.add(prev)
	current = list(d[prev]).pop()
	print('YES')
	while True:
		line.append(current)
		used.add(current)
		next = d[current]
		if len(next) == 1:
			break
		else:
			next = next - used
			prev = current
			current = list(next).pop()
	rest = set(alph) - set(line)
	print(''.join(line) + ''.join(rest))


def findString(graph, letter, parent, idDict, idNum, change):
	if letter in idDict:
		idDict[-1] = 1
		return
	else:
		idDict[letter] = idNum
	adjs = graph[letter]
	if len(adjs) == 1:
		for i in adjs:
			if i != parent:
				findString(graph, i, letter, idDict, idNum + change, change)
	else:
		changes = [1, -1]
		ind = 0
		for i in adjs:
			if parent not in adjs:
				findString(graph, i, letter, idDict, idNum + changes[ind], changes[ind])
				ind += 1
			elif i != parent:
				findString(graph, i, letter, idDict, idNum + change, change)

def findKeyboard(strs):
	graph = {}
	n = len(strs)
	for i in range(n):
		if strs[i] not in graph:
			graph[strs[i]] = set()
		if i - 1 >= 0:
			graph[strs[i]].add(strs[i - 1])
		if i + 1 < n:
			graph[strs[i]].add(strs[i + 1])
	for i in graph:
		if len(graph[i]) > 2:
			return ('NO', '')
	idDict = {}
	ans = ''
	visited = set()
	count = 0
	change = 1
	for i in graph:
		findString(graph, i, -1, idDict, 0, change)
		break
	if -1 in idDict:
		return ('NO', '')
	order = []
	for letter in idDict:
		order.append([idDict[letter], letter])
	order.sort()
	for l in order:
		ans += l[1]
	for l in range(26):
		char = chr(l + ord('a'))
		if char not in idDict:
			ans += char
	return ('YES', ans)

def main():
	t = int(input())
	for _ in range(t):
		password = input()
		ans = findKeyboard(password)
		if ans[0] == 'NO':
			print(ans[0])
		else:
			print(ans[0])
			print(ans[1])
main()


import sys
input = sys.stdin.readline
from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input().strip()
	if len(s) == 1:
		print('YES')
		print('abcdefghijklmnopqrstuvwxyz')
		continue
	d = defaultdict(set)
	b = None
	for c in s:
		if b is None:
			b = c
			continue
		d[c].add(b)
		d[b].add(c)
		b = c
	fns = []
	zns = []
	r = False
	for c in 'abcdefghijklmnopqrstuvwxyz':
		if len(d[c]) >= 3:
			r = True
			break
		if len(d[c]) == 1:
			fns.append(c)
		if not len(d[c]):
			zns.append(c)
	if r:
		print('NO')
		continue
	if len(fns) != 2:
		print('NO')
		continue
	stack = [fns.pop()]
	vs = set()
	while stack:
		v = stack.pop()
		vs.add(v)
		zns.append(v)
		for u in d[v]:
			if u in vs:
				continue
			stack.append(u)
	print('YES')
	print(''.join(zns))


import collections

def reorder(r):
	v1_k = []
	v2_k = []
	if r.__len__() == 0:
		return ''
	for pt in r:
		if r[pt].__len__() == 1:
			v1_k.append(pt)
		elif r[pt].__len__() == 2:
			v2_k.append(pt)
		else:
			return -1
	if v1_k.__len__() != 2:
		return -1
	left = v1_k[0]
	right = v1_k[1]
	ans = left
	new_vis = {}
	p = left
	new_vis[p] = 1
	while new_vis.__len__() != r.__len__():
		for q in r[p]:
			if q not in new_vis:
				p = q
				new_vis[p] = 1
				ans += p
	return ans

def perfect_keyboard(s):
	r = collections.defaultdict(set)
	for (c1, c2) in zip(s[:-1], s[1:]):
		r[c1].add(c2)
		r[c2].add(c1)
	others = ''
	for i in range(26):
		c = chr(ord('a') + i)
		if c in r:
			continue
		others += c
	ans = ''
	tmp = reorder(r)
	if tmp == -1:
		return ('NO', -1)
	ans += tmp
	return ('YES', ans + others)
t = int(input())
for _ in range(t):
	s = input()
	(ok, ans) = perfect_keyboard(s)
	if ok == 'NO':
		print('NO')
	else:
		print('YES')
		print(ans)


from collections import defaultdict
bad = False

def dfs(node, g, par, vis):
	r = ''
	global bad
	l = ''
	cnt = 0
	vis[node] = 1
	for i in g[node]:
		if i == par:
			continue
		if vis[i] == 0:
			if cnt == 0:
				l += dfs(i, g, node, vis)
				cnt = 1
			else:
				r += dfs(i, g, node, vis)
		else:
			bad = True
	return l + chr(node + ord('a')) + r[::-1]

def f(s):
	global bad
	bad = False
	st = set(list('abcdefghijklmnopqrstuvwxyz'))
	np = st.difference(set(s))
	g = defaultdict(set)
	for i in range(len(s) - 1):
		oa = ord(s[i]) - ord('a')
		ob = ord(s[i + 1]) - ord('a')
		g[oa].add(ob)
		g[ob].add(oa)
		if len(g[oa]) > 2 or len(g[ob]) > 2:
			print('NO')
			return ''
	start = ord(s[-1]) - ord('a')
	color = [0] * 26
	ans = dfs(start, g, -1, color)
	if bad:
		print('NO')
		return ''
	for i in np:
		ans += i
	print('YES')
	print(ans)
	return ''
for i in range(int(input())):
	print(f(input()))


def add(v, u):
	if len(d[v]) == 2 and u not in d[v]:
		return False
	else:
		d[v].add(u)
		d[u].add(v)
		return True
alpha = set((chr(i) for i in range(97, 123)))
t = int(input())
d = dict()
for _ in range(t):
	s = input()
	n = len(s)
	if n == 1:
		print('YES')
		print(*alpha, sep='')
		continue
	f = True
	s1 = set([i for i in s])
	d = {i: set() for i in s1}
	for i in range(1, n):
		if not add(s[i - 1], s[i]):
			f = False
			break
	if not f:
		print('NO')
		continue
	count = 0
	start = ''
	for (k, v) in d.items():
		if len(v) == 1:
			start = k
			count += 1
	if count < 2:
		print('NO')
		continue
	print('YES')
	needset = set()
	print(start, end='')
	prev = start
	start = d[start].pop()
	k = start
	while len(d[k]) > 0:
		print(k, end='')
		x = d[k].pop()
		if x == prev:
			if len(d[k]) > 0:
				x = d[k].pop()
			else:
				break
		prev = k
		k = x
	print(*alpha - s1, sep='')


import sys

def input():
	return sys.stdin.readline().rstrip()
DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)]
ALPHABET_SIZE = 26

def slv() -> int:
	s = input()
	n = len(s)
	g = [[] for i in range(ALPHABET_SIZE)]
	filled = [[False] * ALPHABET_SIZE for i in range(ALPHABET_SIZE)]
	for i in range(n - 1):
		(u, v) = (s[i], s[i + 1])
		(u, v) = (ord(u) - ord('a'), ord(v) - ord('a'))
		if filled[u][v] == False:
			filled[u][v] = filled[v][u] = True
			g[u].append(v)
			g[v].append(u)
	if all((len(g[i]) <= 2 for i in range(ALPHABET_SIZE))):
		visited = [False] * ALPHABET_SIZE
		ans = []
		for i in range(ALPHABET_SIZE):
			if visited[i] == True or len(g[i]) > 1:
				continue
			char = i
			visited[i] = True
			while True:
				ans.append(char)
				if all((visited[adj] == True for adj in g[char])):
					break
				else:
					for adj in g[char]:
						if visited[adj] == False:
							visited[adj] = True
							char = adj
		retval = ''
		for char in ans:
			retval += chr(char + ord('a'))
		if len(retval) == ALPHABET_SIZE:
			print('YES')
			print(retval)
		else:
			print('NO')
	else:
		print('NO')
	return 0

def main() -> int:
	t = int(input())
	for i in range(t):
		slv()
	return 0
main()


for _ in range(int(input())):
	s = input()
	sosed = {}
	alp = 'qazwsxedcrfvtgbyhnujmikolp'
	for c in alp:
		sosed[c] = set()
	ans = 'YES'
	for i in range(len(s)):
		if i:
			sosed[s[i]].add(s[i - 1])
			sosed[s[i - 1]].add(s[i])
		if i + 1 != len(s):
			sosed[s[i]].add(s[i + 1])
			sosed[s[i + 1]].add(s[i])
	st = []
	for c in alp:
		if len(sosed[c]) >= 3:
			ans = 'NO'
		elif len(sosed[c]) != 2:
			st.append(c)
	if len(st) < 2:
		ans = 'NO'
	if ans == 'NO':
		print(ans)
	else:
		(s, f) = (st[0], st[1])
		us = set()
		ya = ''
		ir = {}
		for _ in range(26):
			ya += s
			ir[s] = _
			us.add(s)
			kz = 1
			for p in sosed[s]:
				if p not in us:
					s = p
					kz = 0
					break
			if kz:
				kz = 1
				for p in alp:
					if p not in us and len(sosed[p]) < 2:
						s = p
						kz = 0
						break
			if kz:
				for p in alp:
					if p not in us:
						s = p
						break
		for x in alp:
			for y in sosed[x]:
				if abs(ir[x] - ir[y]) > 1:
					ans = 'NO'
		if ans == 'NO':
			print(ans)
		else:
			print('YES')
			print(ya)


from collections import defaultdict
keyboard = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(int(input())):
	pwd = input()
	n = len(pwd)
	if n == 1:
		print('YES')
		print(keyboard)
		continue
	neigh = defaultdict(set)
	neigh[pwd[0]].add(pwd[1])
	neigh[pwd[-1]].add(pwd[-2])
	for i in range(1, n - 1):
		neigh[pwd[i]].add(pwd[i - 1])
		neigh[pwd[i]].add(pwd[i + 1])
	imposs = False
	for (key, val) in neigh.items():
		if len(val) > 2:
			imposs = True
			break
		neigh[key] = list(val)
	if imposs:
		print('NO')
		continue
	pwd_str = [pwd[0]]
	stk = [pwd[0]]
	while len(stk) > 0:
		k = stk.pop(0)
		for nbr in neigh[k]:
			idx = pwd_str.index(k)
			if nbr in pwd_str:
				if nbr == pwd_str[idx - 1]:
					continue
				elif idx != len(pwd_str) - 1 and nbr == pwd_str[idx + 1]:
					continue
				else:
					imposs = True
					break
			elif idx == 0:
				pwd_str.insert(0, nbr)
				stk.append(nbr)
			else:
				pwd_str.insert(len(pwd_str), nbr)
				stk.append(nbr)
		if imposs:
			break
	if imposs:
		print('NO')
		continue
	layout = pwd_str
	for a in list(keyboard):
		if a not in pwd_str:
			layout.append(a)
	print('YES')
	print(''.join(layout))


a = 'abcdefghijklmnopqrstuvwxyz'
t = int(input())
for i in range(t):
	s = input()
	l = s[0]
	p = 0
	flag = True
	for j in range(1, len(s)):
		if p > 0 and s[j] == l[p - 1]:
			p -= 1
		elif p < len(l) - 1 and s[j] == l[p + 1]:
			p += 1
		elif p == len(l) - 1 and s[j] not in l:
			p += 1
			l += s[j]
		elif p == 0 and s[j] not in l:
			l = s[j] + l
		else:
			flag = False
			break
	b = ''
	for c in a:
		if c not in l:
			l += c
	if flag:
		print('YES\n' + l)
	else:
		print('NO')


from collections import deque

def inp(dtype=str, strip=True):
	s = input()
	res = [dtype(p) for p in s.split()]
	res = res[0] if len(res) == 1 and strip else res
	return res

def problemA():
	t = int(input())
	for _ in range(t):
		s = input()
		res = 0
		for i in range(s.find('1'), s.rfind('1')):
			res += int(s[i] == '0')
		print(res)

def problemB():
	t = int(input())
	for _ in range(t):
		(n, g, b) = inp(int)
		hq = (n + 1) // 2
		hq_days = (hq - 1) // g * (g + b) + (hq - 1) % g + 1
		res = max(n, hq_days)
		print(res)

def problemC():
	t = int(input())
	for _ in range(t):
		s = input()
		q = deque()
		q.append(s[0])
		pos = 0
		res = 'YES'
		for symb in s[1:]:
			r = min(len(q) - 1, pos + 1)
			l = max(0, pos - 1)
			if symb == q[r]:
				pos = r
			elif symb == q[l]:
				pos = l
			elif symb in q:
				res = 'NO'
				break
			elif r == pos:
				q.append(symb)
				pos += 1
			elif l == pos:
				q.appendleft(symb)
				pos = 0
			else:
				res = 'NO'
				break
		print(res)
		if res == 'YES':
			for i in range(26):
				letter = chr(i + ord('a'))
				if letter not in q:
					q.append(letter)
			print(''.join(q))
problemC()


def tokeyboard(ls):
	res = ''
	for i in range(97, 123):
		if not chr(i) in ls:
			res += chr(i)
	return ''.join(ls) + res
t = int(input().strip())
for i in range(t):
	res = []
	s = input().strip()
	o = s[0]
	res.append(o)
	possible = True
	for c in s[1:]:
		if not c in res:
			ser = res.index(o)
			if ser != 0:
				if ser == len(res) - 1:
					res.append(c)
				else:
					possible = False
					break
			else:
				res.insert(ser, c)
		elif abs(res.index(c) - res.index(o)) > 1:
			possible = False
			break
		o = c
	if possible:
		print('YES')
		print(tokeyboard(res))
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	v = [0] * 26
	mat = [[] for i in range(26)]
	ans = ''
	s1 = ''
	start = -1
	for i in range(len(s) - 1):
		if s[i + 1] not in mat[ord(s[i]) - ord('a')]:
			if len(mat[ord(s[i]) - ord('a')]) == 2:
				ans = 'NO'
				break
			else:
				mat[ord(s[i]) - ord('a')].append(s[i + 1])
		if s[i] not in mat[ord(s[i + 1]) - ord('a')]:
			if len(mat[ord(s[i + 1]) - ord('a')]) == 2:
				ans = 'NO'
				break
			else:
				mat[ord(s[i + 1]) - ord('a')].append(s[i])
	if ans != 'NO':
		for i in range(26):
			if len(mat[i]) == 1:
				start = i
				break
		if start == -1:
			ans = 'NO'
		else:
			q = start
			v[start] = 1
			s1 += chr(start + ord('a'))
			while q != -1:
				count = 0
				ind = q
				q = -1
				if len(mat[ind]) == 2:
					if v[ord(mat[ind][0]) - ord('a')] and v[ord(mat[ind][1]) - ord('a')] == 1:
						ans = 'NO'
						break
				for c in mat[ind]:
					if v[ord(c) - ord('a')] == 1:
						continue
					v[ord(c) - ord('a')] = 1
					s1 += c
					q = ord(c) - ord('a')
	if ans == 'NO' and len(s) != 1:
		print(ans)
	else:
		print('YES')
		for i in range(len(mat)):
			if len(mat[i]) == 0:
				s1 += chr(i + ord('a'))
		print(s1)