#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define FAST_IO ios_base::sync_with_stdio(),cout.tie(NULL),cin.tie(NULL);
set<int>g[26];
bool visited[26];
bool pos = true;
string final;

bool dfs(int src, int parent) {
	visited[src] = true;
	final += 'a' + src;
	if (g[src].size() > 2)
	{
		pos = false;
	}
	for (auto x : g[src]) {
		if (!visited[x]) {
			if (dfs(x, src))return true;
		}
		else if (x != parent)return true;
	}
	return false;
}
int main()
{
	FAST_IO;
	int t;
	cin >> t;
	while (t--) {
		final = "";
		pos = true;
		memset(visited, false, sizeof(visited));
		for (int i = 0; i < 26; i++)g[i].clear();
		string s;
		cin >> s;
		int n = s.length();
		int src = 0;
		for (int i = 1; i < n; i++)
		{
			int u = s[i - 1] - 'a';
			int v = s[i] - 'a';
			g[u].insert(v);
			g[v].insert(u);
		}
		int cnt = 26;
		for (int i = 0; i < s.length(); i++)
		{
			if (!visited[s[i] - 'a']) {
				pos &= !dfs(i, -1);
			}
		}

		if (pos) {
			cout << "YES" << endl;
			cout << final << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define FAST_IO ios_base::sync_with_stdio(),cout.tie(NULL),cin.tie(NULL);
set<int>g[26];
bool visited[26];
bool pos = true;
string final;
void dfs(int src) {
	visited[src] = true;
	final += 'a' + src;
	for (auto x : g[src]) {
		if (!visited[x]) {
			(dfs(x));
		}
	}
}

int main()
{
	FAST_IO;
	int t;
	cin >> t;
	while (t--) {
		final = "";
		pos = true;
		memset(visited, false, sizeof(visited));
		for (int i = 0; i < 26; i++)g[i].clear();
		string s;
		cin >> s;
		int n = s.length();
		for (int i = 1; i < n; i++)
		{
			int u = s[i - 1] - 'a';
			int v = s[i] - 'a';
			g[u].insert(v);
			g[v].insert(u);
		}
		int src = -1;
		for (int i = 0; i < 26; i++)
		{
			if (g[i].size() > 2)
			{
				pos = false;
			}
			if (g[i].size() == 1)
			{
				src = i;
			}
		}
		if (src == -1 && s.length() > 1)pos = false;
		else dfs(src);
		for (int i = 0; i < 26; i++) {
			if (!visited[i]) {
				final += i + 'a';
			}
		}
		if (pos) {
			cout << "YES" << endl;
			cout << final << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define FAST_IO ios_base::sync_with_stdio(),cout.tie(NULL),cin.tie(NULL);
set<int>g[29];
bool visited[29];
bool pos = true;
string final;
bool dfs(int src, int parent) {
	visited[src] = true;
	final += 'a' + src;
	if (g[src].size() > 2)
	{
		pos = false;
	}
	for (auto x : g[src]) {
		if (!visited[x]) {
			if (dfs(x, src))return true;
		}
		else if (x != parent)return true;
	}
	return false;
}

int main()
{
	FAST_IO;
	int t;
	cin >> t;
	while (t--) {
		final = "";
		pos = true;
		memset(visited, false, sizeof(visited));
		for (int i = 0; i < 26; i++)g[i].clear();
		string s;
		cin >> s;
		int n = s.length();
		int src = 0;
		for (int i = 1; i < n; i++)
		{
			int u = s[i - 1] - 'a';
			int v = s[i] - 'a';
			g[u].insert(v);
			g[v].insert(u);
		}
		int cnt = 26;
		for (int i = 0; i < 26; i++)
		{
			if (g[s[i] - 'a'].size() == 1) {
				src = s[i] - 'a';
				break;
			}
		}
		pos &= !dfs(src, -1);
		for (int i = 0; i < 26; i++) {
			if (!visited[i]) {
				final += i + 'a';
			}
		}
		if (pos) {
			cout << "YES" << endl;
			cout << final << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define FAST_IO ios_base::sync_with_stdio(),cout.tie(NULL),cin.tie(NULL);
set<int>g[29];
bool visited[29];
bool pos = true;
string final;

bool dfs(int src, int parent) {
	visited[src] = true;
	final += 'a' + src;
	if (g[src].size() > 2)
	{
		pos = false;
	}
	for (auto x : g[src]) {
		if (!visited[x]) {
			if (dfs(x, src))return true;
		}
		else if (x != parent)return true;
	}
	return false;
}
int main()
{
	FAST_IO;
	int t;
	cin >> t;
	while (t--) {
		final = "";
		pos = true;
		memset(visited, false, sizeof(visited));
		for (int i = 0; i < 26; i++)g[i].clear();
		string s;
		cin >> s;
		int n = s.length();
		int src = 0;
		for (int i = 1; i < n; i++)
		{
			int u = s[i - 1] - 'a';
			int v = s[i] - 'a';
			g[u].insert(v);
			g[v].insert(u);
		}
		int cnt = 26;
		for (int i = 0; i < s.length(); i++)
		{
			if (!visited[s[i] - 'a']) {
				pos &= !dfs(s[i] - 'a', -1);
			}
		}
		for (int i = 0; i < 26; i++) {
			if (!visited[i]) {
				final += 'a' + i;
			}
		}
		if (pos) {
			cout << "YES" << endl;
			cout << final << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define FAST_IO ios_base::sync_with_stdio(),cout.tie(NULL),cin.tie(NULL);
set<int>g[26];
bool visited[26];
bool pos = true;
string final;

void dfs(int src) {
	visited[src] = true;
	final += 'a' + src;
	if (g[src].size() > 2)
	{
		pos = false;
	}
	for (auto x : g[src]) {
		if (!visited[x]) {
			dfs(x);
		}
	}
}
bool isLinear(int V) {
	if (V == 1)
		return true;
	int count = 0;
	for (int i = 0; i < 26; i++) {
		if (g[i].size() == 2)
			count++;
	}
	if (count == V - 2)
		return true;
	else
		return false;
}
int main()
{
	FAST_IO;
	int t;
	cin >> t;
	while (t--) {
		final = "";
		pos = true;
		memset(visited, false, sizeof(visited));
		for (int i = 0; i < 26; i++)g[i].clear();
		string s;
		cin >> s;
		int n = s.length();
		int src = 0;
		for (int i = 1; i < n; i++)
		{
			int u = s[i - 1] - 'a';
			int v = s[i] - 'a';
			g[u].insert(v);
			g[v].insert(u);
		}
		int cnt = 26;
		for (int i = 0; i < 26; i++)
		{
			int l = final.length();
			if (!visited[i]) {
				dfs(i);
				if (l + 1 == final.length())cnt--;
			}
		}

		if (isLinear(cnt)) {
			cout << "YES" << endl;
			cout << final << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define FAST_IO ios_base::sync_with_stdio(),cout.tie(NULL),cin.tie(NULL);
set<int>g[26];
bool visited[26];
bool pos = true;
string final;
void dfs(int src) {
	visited[src] = true;
	final += 'a' + src;
	for (auto x : g[src]) {
		if (!visited[x]) {
			(dfs(x));
		}
	}
}

int main()
{
	FAST_IO;
	int t;
	cin >> t;
	while (t--) {
		final = "";
		pos = true;
		memset(visited, false, sizeof(visited));
		for (int i = 0; i < 26; i++)g[i].clear();
		string s;
		cin >> s;
		int n = s.length();
		for (int i = 1; i < n; i++)
		{
			int u = s[i - 1] - 'a';
			int v = s[i] - 'a';
			g[u].insert(v);
			g[v].insert(u);
		}
		int src = -1;
		for (int i = 0; i < 26; i++)
		{
			if (g[i].size() > 2)
			{
				pos = false;
			}
			if (!visited[i] && g[i].size() < 2)
			{
				dfs(i);
			}
		}
		for (int i = 0; i < 26; i++) {
			if (!visited[i]) {
				pos = false;
			}
		}
		if (pos) {
			cout << "YES" << endl;
			cout << final << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define FAST_IO ios_base::sync_with_stdio(),cout.tie(NULL),cin.tie(NULL);
set<int>g[26];
bool visited[26];
bool pos = true;
string final;
void dfs(int src) {
	visited[src] = true;
	final += 'a' + src;
	for (auto x : g[src]) {
		if (!visited[x]) {
			(dfs(x));
		}
	}
}

int main()
{
	FAST_IO;
	int t;
	cin >> t;
	while (t--) {
		final = "";
		pos = true;
		memset(visited, false, sizeof(visited));
		for (int i = 0; i < 26; i++)g[i].clear();
		string s;
		cin >> s;
		int n = s.length();
		for (int i = 1; i < n; i++)
		{
			int u = s[i - 1] - 'a';
			int v = s[i] - 'a';
			g[u].insert(v);
			g[v].insert(u);
		}
		int src = -1;
		for (int i = 0; i < 26; i++)
		{
			if (g[i].size() > 2)
			{
				pos = false;
			}
			if (!visited[i] && g[i].size() < 2)
			{
				dfs(i);
			}
		}
		for (int i = 0; i < 26; i++) {
			if (!visited[i]) {
				final += i + 'a';
			}
		}
		if (pos) {
			cout << "YES" << endl;
			cout << final << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <deque>
#include <string>
#define int long long
using namespace std;
int T;
int vis[26];
int xp[26][26];
int aaron[100];
int ss;
int e;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> T;
	while (T--)
	{
		int i;
		memset(xp, 0, sizeof(xp));
		memset(aaron, 0, sizeof(aaron));
		for (i = 0; i < 26; i++)
		{
			vis[i] = 0;
		}
		string s;
		cin >> s;
		int t = s.size();
		aaron[30] = s[0]-'a';
		ss = 30;
		e = 30;
		for (i = 1; i < t; i++)
		{
			if(i!=1)
				vis[s[i - 2] - 'a'] = 1;
			if (xp[s[i - 1]-'a'][s[i]-'a'] || xp[s[i]-'a'][s[i - 1]-'a'])
				continue;
			if (vis[s[i]-'a'])
			{
				cout << "NO" << '\n';
				goto T;
			}
			if (aaron[ss] == s[i - 1]-'a')
			{
				ss--;
				aaron[ss] = s[i]-'a';
			}
			else if(aaron[e]==s[i-1]-'a')
			{
				e++;
				aaron[e] = s[i]-'a';
			}
			else
			{
				cout << "NO" << '\n';
				goto T;
			}
			xp[s[i - 1] - 'a'][s[i] - 'a'] = 1;
			xp[s[i] - 'a'][s[i - 1] - 'a'] = 1;
		}
		vis[s[t - 1]-'a'] = 1;
		cout << "YES" << '\n';
		for (i = ss; i <= e; i++)
			cout << (char)(aaron[i] + 'a');
		for (i = 0; i < 26; i++)
		{
			if (!vis[i])
				cout << (char)(i + 'a');
		}
		cout << '\n';
	T:
		int d;
	}
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <string>
#define int long long
using namespace std;
int T;
vector<int>tt[26];
int vis[26];
int have[26][26];
void dfs(int n)
{
	if (vis[n])
		return;
	cout << (char)(n + 'a');
	vis[n] = 1;
	int i;
	for (i = 0; i < tt[n].size(); i++)
	{
		dfs(tt[n][i]);
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> T;
	while (T--)
	{
		int i;
		memset(have, 0, sizeof(have));
		for (i = 0; i < 26; i++)
		{
			tt[i].clear();
			vis[i] = 0;
		}
		string s;
		cin >> s;

		int t = s.size();
		for (i = 1; i < t; i++)
		{
			if (have[s[i] - 'a'][s[i - 1] - 'a'])
				continue;
			tt[s[i] - 'a'].push_back(s[i - 1] - 'a');
			tt[s[i-1] - 'a'].push_back(s[i] - 'a');
			have[s[i] - 'a'][s[i - 1] - 'a'] = 1;
			have[s[i - 1] - 'a'][s[i] - 'a'] = 1;
		}
		int c1 = 0;
		for (i = 0; i < 26; i++)
		{
			if (tt[i].size() >= 3)
			{
				cout << "NO" << '\n';
				goto T;
			}
			if (tt[i].size() == 1)
				c1++;
		}
		if (c1 != 2)
		{
			cout << "NO" << '\n';
			goto T;
		}
		cout << "YES" << '\n';
		for (i = 0; i < 26; i++)
		{
			if (tt[i].size() == 1)
			{
				dfs(i);
				break;
			}
		}
		for (i = 0; i < 26; i++)
		{
			if (!vis[i])
				cout << (char)('a' + i);
		}
		cout << '\n';
	T:
		int d;
	}
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <deque>
#include <string>
#define int long long
using namespace std;
int T;
int vis[26];
int xp[26][26];
int aaron[100];
int ss;
int e;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> T;
	while (T--)
	{
		int i;
		memset(xp, 0, sizeof(xp));
		memset(aaron, 0, sizeof(aaron));
		for (i = 0; i < 26; i++)
		{
			vis[i] = 0;
		}
		string s;
		cin >> s;
		int t = s.size();
		aaron[30] = s[0]-'a';
		ss = 30;
		e = 30;
		for (i = 1; i < t; i++)
		{
			if(i!=1)
				vis[s[i - 2] - 'a'] = 1;
			if (xp[s[i - 1]-'a'][s[i]-'a'] || xp[s[i]-'a'][s[i - 1]-'a'])
				continue;
			if (vis[s[i]-'a'])
			{
				cout << "NO" << '\n';
				goto T;
			}
			if (aaron[ss] == s[i - 1]-'a')
			{
				ss--;
				aaron[ss] = s[i]-'a';
			}
			else
			{
				e++;
				aaron[e] = s[i]-'a';
			}

			xp[s[i - 1] - 'a'][s[i] - 'a'] = 1;
			xp[s[i] - 'a'][s[i - 1] - 'a'] = 1;
		}
		vis[s[t - 1]-'a'] = 1;
		cout << "YES" << '\n';
		for (i = ss; i <= e; i++)
			cout << (char)(aaron[i] + 'a');
		for (i = 0; i < 26; i++)
		{
			if (!vis[i])
				cout << (char)(i + 'a');
		}
		cout << '\n';
	T:
		int d;
	}
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <string>
#define int long long
using namespace std;
int T;
vector<int>tt[26];
int vis[26];
int have[26][26];
void dfs(int n)
{
	if (vis[n])
		return;
	cout << (char)(n + 'a');
	vis[n] = 1;
	int i;
	for (i = 0; i < tt[n].size(); i++)
	{
		dfs(tt[n][i]);
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> T;
	while (T--)
	{
		int i;
		memset(have, 0, sizeof(have));
		for (i = 0; i < 26; i++)
		{
			tt[i].clear();
			vis[i] = 0;
		}
		string s;
		cin >> s;
		int t = s.size();
		if (t == 1)
		{
			cout << "YES" << '\n' << "edocabfghijklmnpqrstuvwxyz" << '\n';
			break;
		}
		for (i = 1; i < t; i++)
		{
			if (have[s[i] - 'a'][s[i - 1] - 'a'])
				continue;
			tt[s[i] - 'a'].push_back(s[i - 1] - 'a');
			tt[s[i - 1] - 'a'].push_back(s[i] - 'a');
			have[s[i] - 'a'][s[i - 1] - 'a'] = 1;
			have[s[i - 1] - 'a'][s[i] - 'a'] = 1;
		}
		int c1 = 0;
		for (i = 0; i < 26; i++)
		{
			if (tt[i].size() >= 3)
			{
				cout << "NO" << '\n';
				goto T;
			}
			if (tt[i].size() == 1)
				c1++;
		}
		if (c1 != 2)
		{
			cout << "NO" << '\n';
			goto T;
		}
		cout << "YES" << '\n';
		for (i = 0; i < 26; i++)
		{
			if (tt[i].size() == 1)
			{
				dfs(i);
				break;
			}
		}
		for (i = 0; i < 26; i++)
		{
			if (!vis[i])
				cout << (char)('a' + i);
		}
		cout << '\n';
	T:
		int d;
	}
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <deque>
#include <string>
#define int long long
using namespace std;
int T;
int vis[26];
int aaron[100];
int ss;
int e;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> T;
	while (T--)
	{
		int i;
		memset(aaron, -1, sizeof(aaron));
		for (i = 0; i < 26; i++)
		{
			vis[i] = 0;
		}
		string s;
		cin >> s;
		int t = s.size();
		aaron[30] = s[0]-'a';
		ss = 30;
		e = 30;
		int curr = 30;
		for (i = 1; i < t; i++)
		{
			if (aaron[curr - 1] == s[i] - 'a')
				curr--;
			else if (aaron[curr + 1] == s[i] - 'a')
				curr++;
			else
			{
				if (vis[s[i] - 'a'])
				{
					cout << "NO" << '\n';
					goto T;
				}
				if (curr == ss)
				{
					ss--;
					aaron[ss] = s[i] - 'a';
					curr--;
				}
				else if (curr == e)
				{
					e++;
					aaron[e] = s[i] - 'a';
					curr++;
				}
				else
				{
					cout << "NO" << '\n';
					goto T;
				}
			}
			vis[s[i] - 'a'] = 1;
		}
		vis[s[0]-'a'] = 1;
		cout << "YES" << '\n';
		for (i = ss; i <= e; i++)
			cout << (char)(aaron[i] + 'a');
		for (i = 0; i < 26; i++)
		{
			if (!vis[i])
				cout << (char)(i + 'a');
		}
		cout << '\n';
	T:
		int d;
	}
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <deque>
#include <string>
#define int long long
using namespace std;
int T;
int vis[26];
int xp[26][26];
int aaron[100];
int ss;
int e;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> T;
	while (T--)
	{
		int i;
		memset(xp, 0, sizeof(xp));
		for (i = 0; i < 26; i++)
		{
			vis[i] = 0;
		}
		ss = 30;
		e = 30;
		string s;
		cin >> s;
		int t = s.size();
		aaron[30] = s[0]-'a';
		ss = 30;
		e = 30;
		for (i = 1; i < t; i++)
		{
			if(i!=1)
				vis[s[i - 2] - 'a'] = 1;
			if (xp[s[i - 1]-'a'][s[i]-'a'] || xp[s[i]-'a'][s[i - 1]-'a'])
				continue;
			if (vis[s[i]-'a'])
			{
				cout << "NO" << '\n';
				goto T;
			}
			if (aaron[ss] == s[i - 1]-'a')
			{
				ss--;
				aaron[ss] = s[i]-'a';
			}
			else
			{
				e++;
				aaron[e] = s[i]-'a';
			}

			xp[s[i - 1] - 'a'][s[i] - 'a'] = 1;
			xp[s[i] - 'a'][s[i - 1] - 'a'] = 1;
		}
		vis[s[t - 1]-'a'] = 1;
		cout << "YES" << '\n';
		for (i = ss; i <= e; i++)
			cout << (char)(aaron[i] + 'a');
		for (i = 0; i < 26; i++)
		{
			if (!vis[i])
				cout << (char)(i + 'a');
		}
		cout << '\n';
	T:
		int d;
	}
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <string>
#define int long long
using namespace std;
int T;
vector<int>tt[26];
int vis[26];
int have[26][26];
void dfs(int n)
{
	if (vis[n])
		return;
	cout << (char)(n + 'a');
	vis[n] = 1;
	int i;
	for (i = 0; i < tt[n].size(); i++)
	{
		dfs(tt[n][i]);
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> T;
	while (T--)
	{
		int i;
		memset(have, 0, sizeof(have));
		for (i = 0; i < 26; i++)
		{
			tt[i].clear();
			vis[i] = 0;
		}
		string s;
		cin >> s;
		int t = s.size();
		if (t == 1)
		{
			cout << "YES" << '\n' << "edocabfghijklmnpqrstuvwxyz" << '\n';
			break;
		}
		for (i = 1; i < t; i++)
		{
			if (have[s[i] - 'a'][s[i - 1] - 'a'])
				continue;
			tt[s[i] - 'a'].push_back(s[i - 1] - 'a');
			tt[s[i - 1] - 'a'].push_back(s[i] - 'a');
			have[s[i] - 'a'][s[i - 1] - 'a'] = 1;
			have[s[i - 1] - 'a'][s[i] - 'a'] = 1;
		}
		int c1 = 0;
		for (i = 0; i < 26; i++)
		{
			if (tt[i].size() >= 3)
			{
				cout << "NO" << '\n';
				goto T;
			}
			if (tt[i].size() == 1)
				c1++;
		}
		if (c1==0)
		{
			cout << "NO" << '\n';
			goto T;
		}
		cout << "YES" << '\n';
		for (i = 0; i < 26; i++)
		{
			if (tt[i].size() == 1&&!vis[i])
			{
				dfs(i);
			}
		}
		for (i = 0; i < 26; i++)
		{
			if (!vis[i])
				cout << (char)('a' + i);
		}
		cout << '\n';
	T:
		int d;
	}
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <deque>
#include <string>
#define int long long
using namespace std;
int T;
int vis[26];
int aaron[100];
int ss;
int e;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> T;
	while (T--)
	{
		int i;
		memset(aaron, -1, sizeof(aaron));
		for (i = 0; i < 26; i++)
		{
			vis[i] = 0;
		}
		string s;
		cin >> s;
		int t = s.size();
		aaron[30] = s[0]-'a';
		ss = 30;
		e = 30;
		int curr = 30;
		vis[s[0] - 'a'] = 1;
		for (i = 1; i < t; i++)
		{
			if (aaron[curr - 1] == s[i] - 'a')
				curr--;
			else if (aaron[curr + 1] == s[i] - 'a')
				curr++;
			else
			{
				if (vis[s[i] - 'a'])
				{
					cout << "NO" << '\n';
					goto T;
				}
				if (curr == ss)
				{
					ss--;
					aaron[ss] = s[i] - 'a';
					curr--;
				}
				else if (curr == e)
				{
					e++;
					aaron[e] = s[i] - 'a';
					curr++;
				}
				else
				{
					cout << "NO" << '\n';
					goto T;
				}
			}
			vis[s[i] - 'a'] = 1;
		}

		cout << "YES" << '\n';
		for (i = ss; i <= e; i++)
			cout << (char)(aaron[i] + 'a');
		for (i = 0; i < 26; i++)
		{
			if (!vis[i])
				cout << (char)(i + 'a');
		}
		cout << '\n';
	T:
		int d;
	}
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <deque>
#include <string>
#define int long long
using namespace std;
int T;
int vis[26];
int xp[26][26];
int aaron[100];
int ss;
int e;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> T;
	while (T--)
	{
		int i;
		memset(xp, 0, sizeof(xp));
		memset(aaron, -1, sizeof(aaron));
		for (i = 0; i < 26; i++)
		{
			vis[i] = 0;
		}
		string s;
		cin >> s;
		int t = s.size();
		aaron[30] = s[0]-'a';
		ss = 30;
		e = 30;
		int curr = 30;
		for (i = 1; i < t; i++)
		{
			if(i!=1)
				vis[s[i - 2] - 'a'] = 1;
			if (aaron[curr - 1] == s[i] - 'a')
				curr--;
			else if (aaron[curr + 1] == s[i] - 'a')
				curr++;
			else
			{
				if (vis[s[i] - 'a'])
				{
					cout << "NO" << '\n';
					goto T;
				}
				if (curr == ss)
				{
					ss--;
					aaron[ss] = s[i] - 'a';
					curr--;
				}
				else if (curr == e)
				{
					e++;
					aaron[e] = s[i] - 'a';
					curr++;
				}
				else
				{
					cout << "NO" << '\n';
					goto T;
				}
			}
		}
		vis[s[t - 1]-'a'] = 1;
		cout << "YES" << '\n';
		for (i = ss; i <= e; i++)
			cout << (char)(aaron[i] + 'a');
		for (i = 0; i < 26; i++)
		{
			if (!vis[i])
				cout << (char)(i + 'a');
		}
		cout << '\n';
	T:
		int d;
	}
}


#include <bits/stdc++.h>
using namespace std;

#define DEBUG printf("Debug line.\n");
#define testcase long long t; cin>>t; while(t--)
#define ll  int
#define nl printf("\n")

string s;
set<ll>x[256];
string ans;
ll chars[256]= {0};

void serial(ll letter)
{
    chars[letter]=1;
    ans+=(char)letter;
    for(auto i : x[letter])
    {
        if(chars[i]!=0)
        {
            serial(i);
        }
    }
}

int main()
{
    testcase
    {
        for(ll i=0; i<256; i++)
        {
            x[i].clear();
        }
        cin>>s;
        for(ll i=0; i<s.size(); i++)
        {
            if(i+1<s.size())
            {
                x[s[i]].insert(s[i+1]);
            }
            if(i-1>=0)
            {
                x[s[i]].insert(s[i-1]);
            }
        }
        ll st;
        bool is_okay=true,one=false;
        for(auto i:s)
        {
            if(x[i].size()>2)
            {
                is_okay=false;
            }
            else if(x[i].size()==1)
            {
                one=true;
                st=i;
            }
        }
        if(!one)
        {
            is_okay=false;
        }
        if(s.size()==1)
        {
            st=s[0];
        }
        if(!is_okay)
        {
            cout<<"NO\n";
        }
        else
        {
            cout<<"YES\n";
            ans="";
            serial(st);
            cout<<ans;
            for(ll i='a';i<='z';i++)
            {
                if(chars[i]==0)
                {
                    printf("%c",i);
                }
            }
            nl;
        }

    }
}


#include <bits/stdc++.h>
using namespace std;

#define DEBUG printf("Debug line.\n");
#define testcase long long t; cin>>t; while(t--)
#define ll  int
#define nl printf("\n")

string s;
set<ll>x[256];
string ans;
ll chars[256]= {0};

void serial(ll letter)
{
    char c=letter;
    chars[letter]=1;
    ans+=c;
    for(auto i : x[letter])
    {
        if(chars[i]==0)
        {
            serial(i);
        }
    }
}

int main()
{
    testcase
    {
        for(ll i=0; i<256; i++)
        {
            x[i].clear();
        }
        cin>>s;
        for(ll i=0; i<s.size(); i++)
        {
            if(i+1<s.size())
            {
                x[s[i]].insert(s[i+1]);
            }
            if(i-1>=0)
            {
                x[s[i]].insert(s[i-1]);
            }
        }
        ll st;
        bool is_okay=true,one=false;
        for(auto i:s)
        {
            if(x[i].size()>2)
            {
                is_okay=false;
            }
            else if(x[i].size()==1)
            {
                one=true;
                st=i;
            }
        }
        if(!one)
        {
            is_okay=false;
        }
        if(s.size()==1)
        {
            st=s[0];
        }
        if(!is_okay)
        {
            cout<<"NO\n";
        }
        else
        {
            cout<<"YES\n";
            ans="";
            serial(st);
            cout<<ans;
            memset(chars,0,sizeof chars);
            for(auto i:ans)
            {
                chars[i]=1;
            }
            for(char i='a';i<='z';i++)
            {
                if(!chars[i])
                {
                    printf("%c",i);
                }
            }
            nl;
        }

    }
}


#include <bits/stdc++.h>
using namespace std;

#define DEBUG printf("Debug line.\n");
#define testcase long long t; cin>>t; while(t--)
#define ll  int
#define nl printf("\n")

string ans="";
set < int > x[200];
bool vis[200];
void dfs(int u)
{
    char c=u;
    ans+=c;
    vis[u]=1;
    for(auto i : x[u])
    {
        if(!vis[i])
            dfs(i);
    }
}

int main()
{
    testcase
    {
        int chars[256];
        memset(chars,0,sizeof(chars));
        string s;
        cin>>s;
        ll checking_pos=0;
        ll left,right;
        bool is_okay=true;

        ll insertt=0;

        bool hmm=false;
        //string ans;

        for(ll i=0; i<s.size() && is_okay; i++)
        {
            if(i!=0)
            {
                if(chars[s[i]]==1)
                {
                    left=checking_pos-1;
                    right=checking_pos+1;
                    if(s[left]==s[i] && left!=i)
                    {
                        checking_pos=left;
                    }
                    else if(s[right]==s[i] && right!=i)
                    {
                        checking_pos=right;
                    }
                    else
                    {
                        is_okay=false;
                    }
                    insertt=ans.find(s[i]);
                    hmm=true;
                }
                else
                {
                    if(chars[s[i]]==0)
                    {
                        chars[s[i]]++;
                    }
                    ans.insert(ans.begin()+insertt,s[i]);
                    checking_pos=i;
                    if(!hmm)
                    {
                        insertt++;
                    }

                }
            }
            if(i==0)
            {
                chars[s[i]]++;
                ans.insert(ans.begin()+insertt,s[i]);
                insertt++;
            }
        }
        if(is_okay)
        {
            printf("YES\n");
            bool ok=true,one=false;
            for(ll i=0; i<200; i++)
                x[i].clear();
            for(ll i=0; i<s.size(); i++)
            {
                if(i+1<s.size())
                {
                    x[s[i]].insert(s[i+1]);
                }
                if(i-1>=0)
                {
                    x[s[i]].insert(s[i-1]);
                }
            }
            ll st;
            for(auto i : s)
            {
                if(x[i].size()>2)
                    ok=false;
                else if(x[i].size()==1)
                    one=true,st=i;
            }
            if(!one)
                ok=false;
            if(s.size()==1)ok=true,st=s[0];
            if(!ok)
            {

            }
            else
            {
                memset(vis,0,sizeof vis);
                ans="";
                dfs(st);
                for(char i='a'; i<='z'; i++)
                {
                    if(!vis[i])ans+=i;
                }
                cout<<ans<<endl;
            }
        }
        else
        {
            printf("NO\n");
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define DEBUG printf("Debug line.\n");
#define testcase long long t; cin>>t; while(t--)
#define ll  int
#define nl printf("\n")

string s;
set<ll>x[256];
string ans;
ll chars[256]= {0};

void serial(ll letter)
{
    char c=letter;
    chars[letter]=1;
    ans+=c;
    for(auto i : x[letter])
    {
        if(chars[i]==0)
        {
            serial(i);
        }
    }
}

int main()
{
    testcase
    {
        for(ll i=0; i<256; i++)
        {
            x[i].clear();
        }
        cin>>s;
        for(ll i=0; i<s.size(); i++)
        {
            if(i+1<s.size())
            {
                x[s[i]].insert(s[i+1]);
            }
            if(i-1>=0)
            {
                x[s[i]].insert(s[i-1]);
            }
        }
        ll st;
        bool is_okay=true,one=false;
        for(auto i:s)
        {
            if(x[i].size()>2)
            {
                is_okay=false;
            }
            else if(x[i].size()==1)
            {
                one=true;
                st=i;
            }
        }
        if(!one)
        {
            is_okay=false;
        }
        if(s.size()==1)
        {
            st=s[0];
        }
        if(!is_okay)
        {
            cout<<"NO\n";
        }
        else
        {
            cout<<"YES\n";
            ans="";
            serial(st);
            cout<<ans;
            for(ll i='a';i<='z';i++)
            {
                if(chars[i]==0)
                {
                    printf("%c",i);
                }
            }
            nl;
        }

    }
}


/*
Rafi Hassan Chowdhury
*/
#include <bits/stdc++.h>
using namespace std;

#define DEBUG printf("Debug line.\n");
#define testcase long long int test; scanf("%lld",&test); while(test--)
#define test_Case long long int T;  scanf("%lld",&T); for(long long int t=1;t<=T;t++)
#define ll long long int
#define nl printf("\n");
#define pi acos(-1)

string s;
set<ll>x[256];
ll chars[256]= {0};
string ans;

void dfs(ll at)
{
    char c=at;
    if(chars[c]==1) return;
    chars[c]=1;
    ans+=c;
    for(auto i:x[at])
    {
        dfs(i);
    }
}

int main()
{
    testcase
    {
        for(ll i=0; i<256; i++)
        {
            x[i].clear();
        }
        cin>>s;
        for(ll i=0; i<s.size(); i++)
        {
            if(i-1>=0)
            {
                x[s[i]].insert(s[i-1]);
            }
            if(i+1<s.size())
            {
                x[s[i]].insert(s[i+1]);
            }
        }
        bool yes=true,one=false;
        ll ch=0;
        for(auto i:s)
        {
            if(x[i].size()>2)
            {
                yes=false;
            }
            else if(x[i].size()==1)
            {
                one=true;
                ch=i;
            }
        }
        if(!one)
        {
            yes=false;
        }
        if(s.size()==1)
        {
            yes=true;
            ch=s[0];
        }

        if(!yes)
        {
            cout<<"NO\n";
        }
        else
        {
            cout<<"YES\n";
            ans="";
            memset(chars,0,sizeof chars);
            dfs(ch);
            for(ll i=0;i<ans.size();i++)
            {
                printf("%c",ans[i]);
            }
            for(ll i='a'; i<='z'; i++)
            {
                if(chars[i]==0)
                {
                    printf("%c",i);
                }
            }
            nl
        }
    }
}


/*
Rafi Hassan Chowdhury
*/
#include <bits/stdc++.h>
using namespace std;

#define DEBUG printf("Debug line.\n");
#define testcase long long int test; scanf("%lld",&test); while(test--)
#define test_Case long long int T;  scanf("%lld",&T); for(long long int t=1;t<=T;t++)
#define ll long long int
#define nl printf("\n");
#define pi acos(-1)

string s;
set<ll>x[256];
ll chars[256]= {0};
string ans;

void dfs(ll at)
{
    char c=at;
    if(chars[c]==1) return;
    chars[c]=1;
    ans+=c;
    for(auto i:x[at])
    {
        dfs(i);
    }
}

int main()
{
    testcase
    {
        for(ll i=0; i<256; i++)
        {
            x[i].clear();
        }
        cin>>s;
        for(ll i=0; i<s.size(); i++)
        {
            if(i-1>=0)
            {
                x[s[i]].insert(s[i-1]);
            }
            if(i+1<s.size())
            {
                x[s[i]].insert(s[i+1]);
            }
        }
        bool yes=true,one=false;
        ll ch=0;
        for(auto i:s)
        {
            if(x[i].size()>2)
            {
                yes=false;
            }
            else if(x[i].size()==1)
            {
                one=true;
                ch=i;
            }
        }
        if(!one)
        {
            yes=false;
        }
        if(s.size()==1)
        {
            ch=s[0];
        }

        if(!yes)
        {
            cout<<"NO\n";
        }
        else
        {
            cout<<"YES\n";
            ans="";
            memset(chars,0,sizeof chars);
            dfs(ch);
            for(ll i=0;i<ans.size();i++)
            {
                printf("%c",ans[i]);
            }
            for(ll i='a'; i<='z'; i++)
            {
                if(chars[i]==0)
                {
                    printf("%c",i);
                }
            }
            nl
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define DEBUG printf("Debug line.\n");
#define testcase long long t; cin>>t; while(t--)
#define ll  int
#define nl printf("\n")

int main()
{
    testcase
    {
        int chars[256];
        memset(chars,0,sizeof(chars));
        string s;
        cin>>s;
        ll checking_pos=0;
        ll left,right;
        bool is_okay=true;

        ll insertt=0;

        bool hmm=false;
        string ans;

        for(ll i=0; i<s.size() && is_okay; i++)
        {
            if(i!=0)
            {
                if(chars[s[i]]==1)
                {
                    left=checking_pos-1;
                    right=checking_pos+1;
                    if(s[left]==s[i] && left!=i)
                    {
                        checking_pos=left;
                    }
                    else if(s[right]==s[i] && right!=i)
                    {
                        checking_pos=right;
                    }
                    else
                    {
                        is_okay=false;
                    }
                    insertt=ans.find(s[i]);
                    hmm=true;
                }
                else
                {
                    if(chars[s[i]]==0)
                    {
                        chars[s[i]]++;
                    }
                    ans.insert(ans.begin()+insertt,s[i]);
                    checking_pos=i;
                   if(!hmm)
                   {
                        insertt++;
                   }

                }
            }
            if(i==0)
            {
                chars[s[i]]++;
                ans.insert(ans.begin()+insertt,s[i]);
                insertt++;
            }
        }
        if(is_okay)
        {
            printf("YES\n");
            for(ll x='a'; x<='z'; x++)
            {
                if(chars[x]!=1)
                {
                    printf("%c",x);
                }
            }
            for(ll i=0; i<ans.size(); i++)
            {
                printf("%c",ans[i]);
            }
            nl;
        }
        else
        {
            printf("NO\n");
        }
    }
}


/*
Rafi Hassan Chowdhury
*/
#include <bits/stdc++.h>
using namespace std;

#define DEBUG printf("Debug line.\n");
#define testcase long long int test; scanf("%lld",&test); while(test--)
#define test_Case long long int T;  scanf("%lld",&T); for(long long int t=1;t<=T;t++)
#define ll long long int
#define nl printf("\n");
#define pi acos(-1)

string s;
set<ll>x[256];
ll chars[256]= {0};
string ans;

void dfs(ll at)
{
    char c=at;
    if(chars[c]==1) return;
    chars[c]=1;
    ans+=c;
    for(auto i:x[at])
    {
        dfs(i);
    }
}

int main()
{
    testcase
    {
        for(ll i=0; i<256; i++)
        {
            x[i].clear();
        }
        cin>>s;
        for(ll i=0; i<s.size(); i++)
        {
            if(i)
            {
                x[s[i]].insert(s[i-1]);
            }
            if(i!=s.size())
            {
                x[s[i]].insert(s[i+1]);
            }
        }
        bool yes=true,one=false;
        ll ch=0;
        for(auto i:s)
        {
            if(x[i].size()>2)
            {
                yes=false;
            }
            else if(x[i].size()==1)
            {
                one=true;
                ch=i;
            }
        }
        if(!one)
        {
            yes=false;
        }
        if(s.size()==1)
        {
            ch=s[0];
        }

        if(!yes)
        {
            cout<<"NO\n";
        }
        else
        {
            cout<<"YES\n";
            ans="";
            memset(chars,0,sizeof chars);
            dfs(ch);
            cout<<ans<<"\b";
            for(ll i='a'; i<='z'; i++)
            {
                if(chars[i]==0)
                {
                    printf("%c",i);
                }
            }
            nl
        }
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#define long long int ll
#define INF 0x3f3f3f
using namespace std;
int G[256][256];
int ans[300];
int vis[30];
int pos=0;
char ss[105];
vector<int> v[30];
void Dfs(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		if(G[x][v[x][i]]==1)
		{
			ans[pos++]='a'+v[x][i];
			G[x][v[x][i]]=G[v[x][i]][x]=2;
			Dfs(v[x][i]);
			return ;
		}
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		memset(G,0,sizeof(G));
		memset(vis,0,sizeof(vis));
		memset(ans,0,sizeof(ans));
		pos=0;
		scanf("%s",ss);
		int len=strlen(ss);
		for(int i=0;i<30;i++)
			v[i].clear();
		for(int i=0;i<len-1;i++)
		{
			if(G[ss[i]-'a'][ss[i+1]-'a']==0)
			{
				v[ss[i]-'a'].push_back(ss[i+1]-'a');
			}
			if(G[ss[i+1]-'a'][ss[i]-'a']==0)
				v[ss[i+1]-'a'].push_back(ss[i]-'a');
			G[ss[i]-'a'][ss[i+1]-'a']=G[ss[i+1]-'a'][ss[i]-'a']=1;
			vis[ss[i]-'a']=1;
		}
		vis[ss[len-1]-'a']=1;
		int id=-1;
		for(int i=0;i<26;i++)
		{
			if(v[i].size()==1)
			{
				id=i;
				break;
			}
			else if(v[i].size()>2)
			{
				id=-1;
				break;
			}
		}
		if(id==-1)
		{
			printf("NO\n");
			continue;
		}
		printf("YES\n");
		ans[pos++]=(char)('a'+id);
		Dfs(id);
		for(int i=0;i<26;i++)
		{
			if(!vis[i])
			{
				ans[pos++]=('a'+i);
			}
		}
		for(int i=0;i<pos;i++)
		{
			printf("%c",(char)ans[i]);
		}
		printf("\n");
	}
	return 0;
}
/*
5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#define long long int ll
#define INF 0x3f3f3f
using namespace std;
int G[256][256];
int ans[300];
int vis[30];
int pos=0;
char ss[105];
vector<int> v[30];
void Dfs(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		if(G[x][v[x][i]]==1)
		{
			ans[pos++]='a'+v[x][i];
			G[x][v[x][i]]=G[v[x][i]][x]=2;
			Dfs(v[x][i]);
			return ;
		}
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		memset(G,0,sizeof(G));
		memset(vis,0,sizeof(vis));
		memset(ans,0,sizeof(ans));
		pos=0;
		scanf("%s",ss);
		int len=strlen(ss);
		for(int i=0;i<30;i++)
			v[i].clear();
		for(int i=0;i<len-1;i++)
		{
			if(G[ss[i]-'a'][ss[i+1]-'a']==0)
			{
				v[ss[i]-'a'].push_back(ss[i+1]-'a');
			}
			if(G[ss[i+1]-'a'][ss[i]-'a']==0)
				v[ss[i+1]-'a'].push_back(ss[i]-'a');
			G[ss[i]-'a'][ss[i+1]-'a']=G[ss[i+1]-'a'][ss[i]-'a']=1;
			vis[ss[i]-'a']=1;
		}
		int id=-1;
		for(int i=0;i<26;i++)
		{
			if(v[i].size()==1)
			{
				id=i;
				break;
			}
			else if(v[i].size()>2)
			{
				id=-1;
				break;
			}
		}
		if(id==-1)
		{
			printf("NO\n");
			continue;
		}
		ans[pos++]=(char)('a'+id);
		Dfs(id);
		for(int i=0;i<26;i++)
		{
			if(!vis[i])
			{
				ans[pos++]=('a'+i);
			}
		}
		for(int i=0;i<pos;i++)
		{
			printf("%c",(char)ans[i]);
		}
		printf("\n");
	}
	return 0;
}
/*
5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#define long long int ll
#define INF 0x3f3f3f
using namespace std;
int G[256][256];
int ans[300];
int vis[30];
int pos=0;
char ss[1005];
vector<int> v[30];
void Dfs(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		if(G[x][v[x][i]]==1)
		{
			ans[pos++]='a'+v[x][i];
			G[x][v[x][i]]=G[v[x][i]][x]=2;
			Dfs(v[x][i]);
			return ;
		}
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		memset(G,0,sizeof(G));
		memset(vis,0,sizeof(vis));
		memset(ans,0,sizeof(ans));
		pos=0;
		scanf("%s",ss);
		int len=strlen(ss);
		if(len==1)
		{
			printf("YES\n");
			for(int i=0;i<26;i++)
				printf("%c",(char)(i+'a'));
			printf("\n");
			continue;
		}
		for(int i=0;i<30;i++)
			v[i].clear();
		for(int i=0;i<len-1;i++)
		{
			if(G[ss[i]-'a'][ss[i+1]-'a']==0)
			{
				v[ss[i]-'a'].push_back(ss[i+1]-'a');
			}
			if(G[ss[i+1]-'a'][ss[i]-'a']==0)
				v[ss[i+1]-'a'].push_back(ss[i]-'a');
			G[ss[i]-'a'][ss[i+1]-'a']=G[ss[i+1]-'a'][ss[i]-'a']=1;
			vis[ss[i]-'a']=1;
		}
		vis[ss[len-1]-'a']=1;
		int id=-1;
		int sign=0;
		for(int i=0;i<26;i++)
		{
			if(v[i].size()==1&&id==-1)
			{
				id=i;
			}
			else if(v[i].size()>2)
			{
				sign=1;
				break;
			}
		}
		if(sign==1||id==-1)
		{
			printf("NO\n");
			continue;
		}
		printf("YES\n");
		ans[pos++]=(char)('a'+id);
		Dfs(id);
		for(int i=0;i<26;i++)
		{
			if(!vis[i])
			{
				ans[pos++]=('a'+i);
			}
		}
		for(int i=0;i<pos;i++)
		{
			printf("%c",(char)ans[i]);
		}
		printf("\n");
	}
	return 0;
}
/*
5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#define long long int ll
#define INF 0x3f3f3f
using namespace std;
int G[256][256];
int ans[300];
int vis[30];
int pos=0;
char ss[1005];
vector<int> v[30];
void Dfs(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		if(G[x][v[x][i]]==1)
		{
			ans[pos++]='a'+v[x][i];
			G[x][v[x][i]]=G[v[x][i]][x]=2;
			Dfs(v[x][i]);
			return ;
		}
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		memset(G,0,sizeof(G));
		memset(vis,0,sizeof(vis));
		memset(ans,0,sizeof(ans));
		pos=0;
		scanf("%s",ss);
		int len=strlen(ss);
		if(len==1)
		{
			printf("YES\n");
			for(int i=0;i<26;i++)
				printf("%c",(char)(i+'a'));
			printf("\n");
			continue;
		}
		for(int i=0;i<30;i++)
			v[i].clear();
		for(int i=0;i<len-1;i++)
		{
			if(G[ss[i]-'a'][ss[i+1]-'a']==0)
			{
				v[ss[i]-'a'].push_back(ss[i+1]-'a');
			}
			if(G[ss[i+1]-'a'][ss[i]-'a']==0)
				v[ss[i+1]-'a'].push_back(ss[i]-'a');
			G[ss[i]-'a'][ss[i+1]-'a']=G[ss[i+1]-'a'][ss[i]-'a']=1;
			vis[ss[i]-'a']=1;
		}
		vis[ss[len-1]-'a']=1;
		int id=-1;
		int sign=0;
		for(int i=0;i<26;i++)
		{
			if(v[i].size()==1&&id==-1)
			{
				id=i;
			}
			else if(v[i].size()>2&&sign==0)
			{
				sign=1;
				break;
			}
		}
		if(sign==1)
		{
			printf("NO\n");
			continue;
		}
		printf("YES\n");
		ans[pos++]=(char)('a'+id);
		Dfs(id);
		for(int i=0;i<26;i++)
		{
			if(!vis[i])
			{
				ans[pos++]=('a'+i);
			}
		}
		for(int i=0;i<pos;i++)
		{
			printf("%c",(char)ans[i]);
		}
		printf("\n");
	}
	return 0;
}
/*
5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#define long long int ll
#define INF 0x3f3f3f
using namespace std;
int G[256][256];
int ans[300];
int vis[30];
int pos=0;
char ss[1005];
vector<int> v[30];
void Dfs(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		if(G[x][v[x][i]]==1)
		{
			ans[pos++]='a'+v[x][i];
			G[x][v[x][i]]=G[v[x][i]][x]=2;
			Dfs(v[x][i]);
			return ;
		}
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		memset(G,0,sizeof(G));
		memset(vis,0,sizeof(vis));
		memset(ans,0,sizeof(ans));
		pos=0;
		scanf("%s",ss);
		int len=strlen(ss);
		if(len==1)
		{
			printf("YES\n");
			for(int i=0;i<26;i++)
				printf("%c",(char)(i+'a'));
			printf("\n");
			continue;
		}
		for(int i=0;i<30;i++)
			v[i].clear();
		for(int i=0;i<len-1;i++)
		{
			if(G[ss[i]-'a'][ss[i+1]-'a']==0)
			{
				v[ss[i]-'a'].push_back(ss[i+1]-'a');
			}
			if(G[ss[i+1]-'a'][ss[i]-'a']==0)
				v[ss[i+1]-'a'].push_back(ss[i]-'a');
			G[ss[i]-'a'][ss[i+1]-'a']=G[ss[i+1]-'a'][ss[i]-'a']=1;
			vis[ss[i]-'a']=1;
		}
		vis[ss[len-1]-'a']=1;
		int id=-1;
		for(int i=0;i<26;i++)
		{
			if(v[i].size()==1)
			{
				id=i;
				break;
			}
			else if(v[i].size()>2)
			{
				id=-1;
				break;
			}
		}
		if(id==-1)
		{
			printf("NO\n");
			continue;
		}
		printf("YES\n");
		ans[pos++]=(char)('a'+id);
		Dfs(id);
		for(int i=0;i<26;i++)
		{
			if(!vis[i])
			{
				ans[pos++]=('a'+i);
			}
		}
		for(int i=0;i<pos;i++)
		{
			printf("%c",(char)ans[i]);
		}
		printf("\n");
	}
	return 0;
}
/*
5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#define long long int ll
#define INF 0x3f3f3f
using namespace std;
int G[256][256];
int ans[300];
int vis[30];
int pos=0;
char ss[105];
vector<int> v[30];
void Dfs(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		if(G[x][v[x][i]]==1)
		{
			ans[pos++]='a'+v[x][i];
			G[x][v[x][i]]=G[v[x][i]][x]=2;
			Dfs(v[x][i]);
			return ;
		}
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		memset(G,0,sizeof(G));
		memset(vis,0,sizeof(vis));
		memset(ans,0,sizeof(ans));
		pos=0;
		scanf("%s",ss);
		int len=strlen(ss);
		for(int i=0;i<30;i++)
			v[i].clear();
		for(int i=0;i<len-1;i++)
		{
			if(G[ss[i]-'a'][ss[i+1]-'a']==0)
			{
				v[ss[i]-'a'].push_back(ss[i+1]-'a');
			}
			if(G[ss[i+1]-'a'][ss[i]-'a']==0)
				v[ss[i+1]-'a'].push_back(ss[i]-'a');
			G[ss[i]-'a'][ss[i+1]-'a']=G[ss[i+1]-'a'][ss[i]-'a']=1;
			vis[ss[i]-'a']=1;
		}
		vis[ss[len-1]-'a']=1;
		int id=-1;
		for(int i=0;i<26;i++)
		{
			if(v[i].size()==1)
			{
				id=i;
				break;
			}
			else if(v[i].size()>2)
			{
				id=-1;
				break;
			}
		}
		if(id==-1)
		{
			printf("NO\n");
			continue;
		}
		ans[pos++]=(char)('a'+id);
		Dfs(id);
		for(int i=0;i<26;i++)
		{
			if(!vis[i])
			{
				ans[pos++]=('a'+i);
			}
		}
		for(int i=0;i<pos;i++)
		{
			printf("%c",(char)ans[i]);
		}
		printf("\n");
	}
	return 0;
}
/*
5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#define long long int ll
#define INF 0x3f3f3f
using namespace std;
int G[256][256];
int ans[300];
int vis[30];
int pos=0;
char ss[1005];
vector<int> v[30];
void Dfs(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		if(G[x][v[x][i]]==1)
		{
			ans[pos++]='a'+v[x][i];
			G[x][v[x][i]]=G[v[x][i]][x]=2;
			Dfs(v[x][i]);
			return ;
		}
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		memset(G,0,sizeof(G));
		memset(vis,0,sizeof(vis));
		memset(ans,0,sizeof(ans));
		pos=0;
		scanf("%s",ss);
		int len=strlen(ss);
		if(len==1)
		{
			for(int i=0;i<26;i++)
				printf("%c",(char)(i+'a'));
			printf("\n");
			continue;
		}
		for(int i=0;i<30;i++)
			v[i].clear();
		for(int i=0;i<len-1;i++)
		{
			if(G[ss[i]-'a'][ss[i+1]-'a']==0)
			{
				v[ss[i]-'a'].push_back(ss[i+1]-'a');
			}
			if(G[ss[i+1]-'a'][ss[i]-'a']==0)
				v[ss[i+1]-'a'].push_back(ss[i]-'a');
			G[ss[i]-'a'][ss[i+1]-'a']=G[ss[i+1]-'a'][ss[i]-'a']=1;
			vis[ss[i]-'a']=1;
		}
		vis[ss[len-1]-'a']=1;
		int id=-1;
		for(int i=0;i<26;i++)
		{
			if(v[i].size()==1)
			{
				id=i;
				break;
			}
			else if(v[i].size()>2)
			{
				id=-1;
				break;
			}
		}
		if(id==-1)
		{
			printf("NO\n");
			continue;
		}
		printf("YES\n");
		ans[pos++]=(char)('a'+id);
		Dfs(id);
		for(int i=0;i<26;i++)
		{
			if(!vis[i])
			{
				ans[pos++]=('a'+i);
			}
		}
		for(int i=0;i<pos;i++)
		{
			printf("%c",(char)ans[i]);
		}
		printf("\n");
	}
	return 0;
}
/*
5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#define long long int ll
#define INF 0x3f3f3f
using namespace std;
int G[256][256];
int ans[300];
int vis[30];
int pos=0;
char ss[1005];
vector<int> v[30];
void Dfs(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		if(G[x][v[x][i]]==1)
		{
			ans[pos++]='a'+v[x][i];
			G[x][v[x][i]]=G[v[x][i]][x]=2;
			Dfs(v[x][i]);
			return ;
		}
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		memset(G,0,sizeof(G));
		memset(vis,0,sizeof(vis));
		memset(ans,0,sizeof(ans));
		pos=0;
		scanf("%s",ss);
		int len=strlen(ss);
		for(int i=0;i<30;i++)
			v[i].clear();
		for(int i=0;i<len-1;i++)
		{
			if(G[ss[i]-'a'][ss[i+1]-'a']==0)
			{
				v[ss[i]-'a'].push_back(ss[i+1]-'a');
			}
			if(G[ss[i+1]-'a'][ss[i]-'a']==0)
				v[ss[i+1]-'a'].push_back(ss[i]-'a');
			G[ss[i]-'a'][ss[i+1]-'a']=G[ss[i+1]-'a'][ss[i]-'a']=1;
			vis[ss[i]-'a']=1;
		}
		vis[ss[len-1]-'a']=1;
		int id=-1;
		for(int i=0;i<26;i++)
		{
			if(v[i].size()==1)
			{
				id=i;
				break;
			}
			else if(v[i].size()>2)
			{
				id=-1;
				break;
			}
		}
		if(id==-1)
		{
			printf("NO\n");
			continue;
		}
		printf("YES\n");
		ans[pos++]=(char)('a'+id);
		Dfs(id);
		for(int i=0;i<26;i++)
		{
			if(!vis[i])
			{
				ans[pos++]=('a'+i);
			}
		}
		for(int i=0;i<pos;i++)
		{
			printf("%c",(char)ans[i]);
		}
		printf("\n");
	}
	return 0;
}
/*
5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#define long long int ll
#define INF 0x3f3f3f
using namespace std;
int G[256][256];
int ans[300];
int vis[30];
int pos=0;
char ss[105];
vector<int> v[30];
int Dfs(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		if(G[x][v[x][i]]==1)
		{
			ans[pos++]='a'+v[x][i];
			G[x][v[x][i]]=G[v[x][i]][x]=2;
			Dfs(v[x][i]);
			return 1;
		}
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		memset(G,0,sizeof(G));
		memset(vis,0,sizeof(vis));
		memset(ans,0,sizeof(ans));
		pos=0;
		scanf("%s",ss);
		int len=strlen(ss);
		for(int i=0;i<30;i++)
			v[i].clear();
		for(int i=0;i<len-1;i++)
		{
			if(G[ss[i]-'a'][ss[i+1]-'a']==0)
			{
				v[ss[i]-'a'].push_back(ss[i+1]-'a');
			}
			if(G[ss[i+1]-'a'][ss[i]-'a']==0)
				v[ss[i+1]-'a'].push_back(ss[i]-'a');
			G[ss[i]-'a'][ss[i+1]-'a']=G[ss[i+1]-'a'][ss[i]-'a']=1;
			vis[ss[i]-'a']=1;
		}
		int id=-1;
		for(int i=0;i<26;i++)
		{
			if(v[i].size()==1)
			{
				id=i;
				break;
			}
			else if(v[i].size()>2)
			{
				id=-1;
				break;
			}
		}
		if(id==-1)
		{
			printf("NO\n");
			continue;
		}
		ans[pos++]=(char)('a'+id);
		Dfs(id);
		for(int i=0;i<26;i++)
		{
			if(!vis[i])
			{
				ans[pos++]=('a'+i);
			}
		}
		for(int i=0;i<pos;i++)
		{
			printf("%c",(char)ans[i]);
		}
		printf("\n");
	}
	return 0;
}


        /*----------------------------------*\
        ******BISMILLAHIR RAHMANIR RAHIM******
        ********************
        *****************
        /*************************************/

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define NL printf("\n")
#define xx first
#define yy second
#define gc getchar
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define scani(x) scanf("%d",&x)
#define scanl(x) scanf("%lld",&x)//scanf("%I64d",&x)
#define scand(x) scanf("%lf",&x)
#define scans(x) scanf("%s",x)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(i=j;i<=k;i++)
#define REV(i,j,k) for(i=j;i>=k;i--)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define cnd tree[idx]
#define lnd tree[idx*2]
#define rnd tree[(idx*2)+1]
#define lndp (idx*2),(b),((b+e)/2)
#define rndp (idx*2+1),((b+e)/2+1),(e)
#define pi 2.0*acos(0.0)
#define MOD 1000000007
#define MAX 100005
#define PRINT_CASE(x) printf("Case %d:",cs);

#define sc1(a)  scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define pi1(a) printf("%lld",a)
#define pi2(a,b) printf("%lld %lld",a,b)
#define pi3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define sp printf(" ")
#define yes printf("YES")
#define no printf("NO")

#define all(v) v.begin(),v.end()

template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b);while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BigMod(T A,T B,T M){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T InvMod (T A,T M){return BigMod(A,M-2,M);}
ll gcdr ( ll a, ll b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}
/*
ll poW(ll x, ll n)
{
    if(n==0)
        return 1;
    else if(n%2==0)
        return poW(x*x,n/2);
    else
        return x*poW(x*x,((n-1)/2));
}
*/
/*
int gcdr ( int a, int b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}

const int maxx=1000000;
int status[(maxx>>5)+2];

bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}
int Set(int N, int pos)
{
    return N=(N|(1<<pos));
}
vector<int>P_list;
void sieve()
{
    int i,j,sqrtN;
    sqrtN=int(sqrt(maxx))+1;
    P_list.push_back(2);
    for(int i=3;i<=maxx;i+=2)
    {
        if(check(status[i>>5],i&31)==0)
        {
            P_list.push_back(i);

            if(i<=sqrtN)
            for(j=i*i;j<=maxx;j+=(i<<1))
            {
                status[j>>5]=Set(status[j>>5],j & 31);
            }
        }
    }
}
*/
ll max(ll a,ll b){
    if(a>b) return a;
        return b;
}
ll min(ll a, ll b){
    if(a<b)return a;
            return b;
}
void FastIO()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.precision(20);
}
const ll size3=300005;
const ll size2=200005;
const ll size1=100005;
/*
void graph(ll n){
    if(n==0) return ;
    for(ll i=0;i<n;i++){
        ll x,y;
        sc2(x,y);
        G[x].pb(y);
        G[y].pb(x);
    }
    return ;
}
*/
set<ll> G[200];
ll visited[200] = {0};
string ss = "";
ll imp = 0;
void dfs(ll curr,ll last) {
    visited[curr] = 1;
    ss += (char)(curr + 'a');
    for(auto it = G[curr].begin(); it != G[curr].end();++it){
        if(visited[*it]==1 && *it!=last){
            imp = 1;
            return ;
        }
        else if(*it!=last)
        dfs(*it,curr);
    }
    return ;
}
int main()
{
    FastIO();
    ll t,i,j,m,x,y,n;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        imp = 0;
        mem(visited,0);
        n = s.size();
        for(i=0;i<199;i++){
            G[i].clear();
        }
        for(i=1;i<n;i++) {
            G[s[i]-'a'].insert(s[i-1]-'a');
            G[s[i-1]-'a'].insert(s[i]-'a');
        }
        vector<string > ans;
        for(i=0;i<26;i++){
            if(visited[i]==0 && G[i].size()==1){
                ss = "";
                dfs(i,i);
                ans.pb(ss);
            }
            else if(visited[i]==0 && G[i].size()==0){
                ss = "";
                ss += (char)(i+'a');
                ans.pb(ss);
            }
        }
        string res = "";
        for(i=0;i<ans.size();i++){
            res += ans[i];
        }
        //cout<<res<<endl;
        if(imp || res.size()<26){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
            cout<<res<<endl;
        }
    }

    return 0;
}


        /*----------------------------------*\
        ******BISMILLAHIR RAHMANIR RAHIM******
        ********************
        *****************
        /*************************************/

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define NL printf("\n")
#define xx first
#define yy second
#define gc getchar
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define scani(x) scanf("%d",&x)
#define scanl(x) scanf("%lld",&x)//scanf("%I64d",&x)
#define scand(x) scanf("%lf",&x)
#define scans(x) scanf("%s",x)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(i=j;i<=k;i++)
#define REV(i,j,k) for(i=j;i>=k;i--)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define cnd tree[idx]
#define lnd tree[idx*2]
#define rnd tree[(idx*2)+1]
#define lndp (idx*2),(b),((b+e)/2)
#define rndp (idx*2+1),((b+e)/2+1),(e)
#define pi 2.0*acos(0.0)
#define MOD 1000000007
#define MAX 100005
#define PRINT_CASE(x) printf("Case %d:",cs);

#define sc1(a)  scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define pi1(a) printf("%lld",a)
#define pi2(a,b) printf("%lld %lld",a,b)
#define pi3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define sp printf(" ")
#define yes printf("YES")
#define no printf("NO")

#define all(v) v.begin(),v.end()

template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b);while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BigMod(T A,T B,T M){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T InvMod (T A,T M){return BigMod(A,M-2,M);}
ll gcdr ( ll a, ll b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}
/*
ll poW(ll x, ll n)
{
    if(n==0)
        return 1;
    else if(n%2==0)
        return poW(x*x,n/2);
    else
        return x*poW(x*x,((n-1)/2));
}
*/
/*
int gcdr ( int a, int b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}

const int maxx=1000000;
int status[(maxx>>5)+2];

bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}
int Set(int N, int pos)
{
    return N=(N|(1<<pos));
}
vector<int>P_list;
void sieve()
{
    int i,j,sqrtN;
    sqrtN=int(sqrt(maxx))+1;
    P_list.push_back(2);
    for(int i=3;i<=maxx;i+=2)
    {
        if(check(status[i>>5],i&31)==0)
        {
            P_list.push_back(i);

            if(i<=sqrtN)
            for(j=i*i;j<=maxx;j+=(i<<1))
            {
                status[j>>5]=Set(status[j>>5],j & 31);
            }
        }
    }
}
*/
ll max(ll a,ll b){
    if(a>b) return a;
        return b;
}
ll min(ll a, ll b){
    if(a<b)return a;
            return b;
}
void FastIO()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.precision(20);
}
const ll size3=300005;
const ll size2=200005;
const ll size1=100005;
/*
void graph(ll n){
    if(n==0) return ;
    for(ll i=0;i<n;i++){
        ll x,y;
        sc2(x,y);
        G[x].pb(y);
        G[y].pb(x);
    }
    return ;
}
*/
set<ll> G[200];
ll visited[200] = {0};
string ss = "";
ll imp = 0;
void dfs(ll curr,ll last) {
    visited[curr] = 1;
    ss += (char)(curr + 'a');
    for(auto it = G[curr].begin(); it != G[curr].end();++it){
        if(visited[*it]==1 && *it != last){
            imp = 1;
            //cout<<curr<<" "<<*it<<endl;
            return ;
        }
        else if( visited[*it]==0)
        dfs(*it,curr);
    }
    return ;
}
int main()
{
    FastIO();
    ll t,i,j,m,x,y,n;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        imp = 0;
        mem(visited,0);
        n = s.size();
        for(i=0;i<199;i++){
            G[i].clear();
        }
        for(i=1;i<n;i++) {
            if(s[i]==s[i-1]){
                continue;
            }
            G[s[i]-'a'].insert(s[i-1]-'a');
            G[s[i-1]-'a'].insert(s[i]-'a');
        }
        vector<string > ans;
        for(i=0;i<26;i++){
            if(visited[i]==0 && G[i].size()==1){
                ss = "";
                dfs(i,i);
                ans.pb(ss);
            }
            else if(visited[i]==0 && G[i].size()==0){
                ss = "";
                ss += (char)(i+'a');
                ans.pb(ss);
            }
        }
        string res = "";
        for(i=0;i<ans.size();i++){
            res += ans[i];
        }
        //cout<<res<<endl;
        if(imp || res.size()<26){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
            cout<<res<<endl;
        }
    }

    return 0;
}


        /*----------------------------------*\
        ******BISMILLAHIR RAHMANIR RAHIM******
        ********************
        *****************
        /*************************************/

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define NL printf("\n")
#define xx first
#define yy second
#define gc getchar
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define scani(x) scanf("%d",&x)
#define scanl(x) scanf("%lld",&x)//scanf("%I64d",&x)
#define scand(x) scanf("%lf",&x)
#define scans(x) scanf("%s",x)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(i=j;i<=k;i++)
#define REV(i,j,k) for(i=j;i>=k;i--)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define cnd tree[idx]
#define lnd tree[idx*2]
#define rnd tree[(idx*2)+1]
#define lndp (idx*2),(b),((b+e)/2)
#define rndp (idx*2+1),((b+e)/2+1),(e)
#define pi 2.0*acos(0.0)
#define MOD 1000000007
#define MAX 100005
#define PRINT_CASE(x) printf("Case %d:",cs);

#define sc1(a)  scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define pi1(a) printf("%lld",a)
#define pi2(a,b) printf("%lld %lld",a,b)
#define pi3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define sp printf(" ")
#define yes printf("YES")
#define no printf("NO")

#define all(v) v.begin(),v.end()

template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b);while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BigMod(T A,T B,T M){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T InvMod (T A,T M){return BigMod(A,M-2,M);}
ll gcdr ( ll a, ll b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}
/*
ll poW(ll x, ll n)
{
    if(n==0)
        return 1;
    else if(n%2==0)
        return poW(x*x,n/2);
    else
        return x*poW(x*x,((n-1)/2));
}
*/
/*
int gcdr ( int a, int b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}

const int maxx=1000000;
int status[(maxx>>5)+2];

bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}
int Set(int N, int pos)
{
    return N=(N|(1<<pos));
}
vector<int>P_list;
void sieve()
{
    int i,j,sqrtN;
    sqrtN=int(sqrt(maxx))+1;
    P_list.push_back(2);
    for(int i=3;i<=maxx;i+=2)
    {
        if(check(status[i>>5],i&31)==0)
        {
            P_list.push_back(i);

            if(i<=sqrtN)
            for(j=i*i;j<=maxx;j+=(i<<1))
            {
                status[j>>5]=Set(status[j>>5],j & 31);
            }
        }
    }
}
*/
ll max(ll a,ll b){
    if(a>b) return a;
        return b;
}
ll min(ll a, ll b){
    if(a<b)return a;
            return b;
}
void FastIO()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.precision(20);
}
const ll size3=300005;
const ll size2=200005;
const ll size1=100005;
/*
void graph(ll n){
    if(n==0) return ;
    for(ll i=0;i<n;i++){
        ll x,y;
        sc2(x,y);
        G[x].pb(y);
        G[y].pb(x);
    }
    return ;
}
*/
set<ll> G[200];
ll visited[200] = {0};
string ss = "";
ll imp = 0;
void dfs(ll curr,ll last) {
    visited[curr] = 1;
    ss += (char)(curr + 'a');
    for(auto it = G[curr].begin(); it != G[curr].end();++it){
        if(visited[*it]==1 && *it != last){
            imp = 1;
            //cout<<curr<<" "<<*it<<endl;
            return ;
        }
        else if( visited[*it]==0)
        dfs(*it,curr);
    }
    return ;
}
int main()
{
    FastIO();
    ll t,i,j,m,x,y,n;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        imp = 0;
        mem(visited,0);
        n = s.size();
        for(i=0;i<199;i++){
            G[i].clear();
        }
        for(i=1;i<n;i++) {
            if(s[i]==s[i-1]){
                continue;
            }
            G[s[i]-'a'].insert(s[i-1]-'a');
            G[s[i-1]-'a'].insert(s[i]-'a');
        }
        vector<string > ans;
        for(i=0;i<26;i++){
            if(G[i].size()>2){
                imp =1 ;
            }
            if(visited[i]==0 && G[i].size()==1){
                ss = "";
                dfs(i,i);
                ans.pb(ss);
            }
            else if(visited[i]==0 && G[i].size()==0){
                ss = "";
                ss += (char)(i+'a');
                ans.pb(ss);
            }
        }
        string res = "";
        for(i=0;i<ans.size();i++){
            res += ans[i];
        }
        //cout<<res<<endl;
        if(imp || res.size()<26){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
            cout<<res<<endl;
        }
    }

    return 0;
}


        /*----------------------------------*\
        ******BISMILLAHIR RAHMANIR RAHIM******
        ********************
        *****************
        /*************************************/

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define NL printf("\n")
#define xx first
#define yy second
#define gc getchar
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define scani(x) scanf("%d",&x)
#define scanl(x) scanf("%lld",&x)//scanf("%I64d",&x)
#define scand(x) scanf("%lf",&x)
#define scans(x) scanf("%s",x)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(i=j;i<=k;i++)
#define REV(i,j,k) for(i=j;i>=k;i--)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define cnd tree[idx]
#define lnd tree[idx*2]
#define rnd tree[(idx*2)+1]
#define lndp (idx*2),(b),((b+e)/2)
#define rndp (idx*2+1),((b+e)/2+1),(e)
#define pi 2.0*acos(0.0)
#define MOD 1000000007
#define MAX 100005
#define PRINT_CASE(x) printf("Case %d:",cs);

#define sc1(a)  scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define pi1(a) printf("%lld",a)
#define pi2(a,b) printf("%lld %lld",a,b)
#define pi3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define sp printf(" ")
#define yes printf("YES")
#define no printf("NO")

#define all(v) v.begin(),v.end()

template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b);while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BigMod(T A,T B,T M){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T InvMod (T A,T M){return BigMod(A,M-2,M);}
ll gcdr ( ll a, ll b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}
/*
ll poW(ll x, ll n)
{
    if(n==0)
        return 1;
    else if(n%2==0)
        return poW(x*x,n/2);
    else
        return x*poW(x*x,((n-1)/2));
}
*/
/*
int gcdr ( int a, int b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}

const int maxx=1000000;
int status[(maxx>>5)+2];

bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}
int Set(int N, int pos)
{
    return N=(N|(1<<pos));
}
vector<int>P_list;
void sieve()
{
    int i,j,sqrtN;
    sqrtN=int(sqrt(maxx))+1;
    P_list.push_back(2);
    for(int i=3;i<=maxx;i+=2)
    {
        if(check(status[i>>5],i&31)==0)
        {
            P_list.push_back(i);

            if(i<=sqrtN)
            for(j=i*i;j<=maxx;j+=(i<<1))
            {
                status[j>>5]=Set(status[j>>5],j & 31);
            }
        }
    }
}
*/
ll max(ll a,ll b){
    if(a>b) return a;
        return b;
}
ll min(ll a, ll b){
    if(a<b)return a;
            return b;
}
void FastIO()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.precision(20);
}
const ll size3=300005;
const ll size2=200005;
const ll size1=100005;
/*
void graph(ll n){
    if(n==0) return ;
    for(ll i=0;i<n;i++){
        ll x,y;
        sc2(x,y);
        G[x].pb(y);
        G[y].pb(x);
    }
    return ;
}
*/
set<ll> G[200];
ll visited[200] = {0};
string ss = "";
ll imp = 0;
void dfs(ll curr,ll last) {
    visited[curr] = 1;
    ss += (char)(curr + 'a');
    for(auto it = G[curr].begin(); it != G[curr].end();++it){
        if(visited[*it]==1 && *it!=last && *it!=curr){
            imp = 1;
            //cout<<*it<<endl;
            return ;
        }
        else if(*it!=last)
        dfs(*it,curr);
    }
    return ;
}
int main()
{
    FastIO();
    ll t,i,j,m,x,y,n;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        imp = 0;
        mem(visited,0);
        n = s.size();
        for(i=0;i<199;i++){
            G[i].clear();
        }
        for(i=1;i<n;i++) {
            if(s[i]==s[i-1]){
                continue;
            }
            G[s[i]-'a'].insert(s[i-1]-'a');
            G[s[i-1]-'a'].insert(s[i]-'a');
        }
        vector<string > ans;
        for(i=0;i<26;i++){
            if(visited[i]==0 && G[i].size()==1){
                ss = "";
                dfs(i,i);
                ans.pb(ss);
            }
            else if(visited[i]==0 && G[i].size()==0){
                ss = "";
                ss += (char)(i+'a');
                ans.pb(ss);
            }
        }
        string res = "";
        for(i=0;i<ans.size();i++){
            res += ans[i];
        }
        //cout<<res<<endl;
        if(imp || res.size()<26){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
            cout<<res<<endl;
        }
    }

    return 0;
}


        /*----------------------------------*\
        ******BISMILLAHIR RAHMANIR RAHIM******
        ********************
        *****************
        /*************************************/

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define NL printf("\n")
#define xx first
#define yy second
#define gc getchar
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define scani(x) scanf("%d",&x)
#define scanl(x) scanf("%lld",&x)//scanf("%I64d",&x)
#define scand(x) scanf("%lf",&x)
#define scans(x) scanf("%s",x)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(i=j;i<=k;i++)
#define REV(i,j,k) for(i=j;i>=k;i--)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define cnd tree[idx]
#define lnd tree[idx*2]
#define rnd tree[(idx*2)+1]
#define lndp (idx*2),(b),((b+e)/2)
#define rndp (idx*2+1),((b+e)/2+1),(e)
#define pi 2.0*acos(0.0)
#define MOD 1000000007
#define MAX 100005
#define PRINT_CASE(x) printf("Case %d:",cs);

#define sc1(a)  scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define pi1(a) printf("%lld",a)
#define pi2(a,b) printf("%lld %lld",a,b)
#define pi3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define sp printf(" ")
#define yes printf("YES")
#define no printf("NO")

#define all(v) v.begin(),v.end()

template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b);while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BigMod(T A,T B,T M){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T InvMod (T A,T M){return BigMod(A,M-2,M);}
ll gcdr ( ll a, ll b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}
/*
ll poW(ll x, ll n)
{
    if(n==0)
        return 1;
    else if(n%2==0)
        return poW(x*x,n/2);
    else
        return x*poW(x*x,((n-1)/2));
}
*/
/*
int gcdr ( int a, int b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}

const int maxx=1000000;
int status[(maxx>>5)+2];

bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}
int Set(int N, int pos)
{
    return N=(N|(1<<pos));
}
vector<int>P_list;
void sieve()
{
    int i,j,sqrtN;
    sqrtN=int(sqrt(maxx))+1;
    P_list.push_back(2);
    for(int i=3;i<=maxx;i+=2)
    {
        if(check(status[i>>5],i&31)==0)
        {
            P_list.push_back(i);

            if(i<=sqrtN)
            for(j=i*i;j<=maxx;j+=(i<<1))
            {
                status[j>>5]=Set(status[j>>5],j & 31);
            }
        }
    }
}
*/
ll max(ll a,ll b){
    if(a>b) return a;
        return b;
}
ll min(ll a, ll b){
    if(a<b)return a;
            return b;
}
void FastIO()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.precision(20);
}
const ll size3=300005;
const ll size2=200005;
const ll size1=100005;
/*
void graph(ll n){
    if(n==0) return ;
    for(ll i=0;i<n;i++){
        ll x,y;
        sc2(x,y);
        G[x].pb(y);
        G[y].pb(x);
    }
    return ;
}
*/
set<ll> G[200];
ll visited[200] = {0};
string ss = "";
ll imp = 0;
void dfs(ll curr,ll last) {
    visited[curr] = 1;
    ss += (char)(curr + 'a');
    for(auto it = G[curr].begin(); it != G[curr].end();++it){
        if(visited[*it]==1 && *it!=last){
            imp = 1;
            //cout<<curr<<" "<<*it<<endl;
            return ;
        }
        else if(*it!=last && visited[*it]==0)
        dfs(*it,curr);
    }
    return ;
}
int main()
{
    FastIO();
    ll t,i,j,m,x,y,n;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        imp = 0;
        mem(visited,0);
        n = s.size();
        for(i=0;i<199;i++){
            G[i].clear();
        }
        for(i=1;i<n;i++) {
            if(s[i]==s[i-1]){
                continue;
            }
            G[s[i]-'a'].insert(s[i-1]-'a');
            G[s[i-1]-'a'].insert(s[i]-'a');
        }
        vector<string > ans;
        for(i=0;i<26;i++){
            if(visited[i]==0 && G[i].size()==1){
                ss = "";
                dfs(i,i);
                ans.pb(ss);
            }
            else if(visited[i]==0 && G[i].size()==0){
                ss = "";
                ss += (char)(i+'a');
                ans.pb(ss);
            }
        }
        string res = "";
        for(i=0;i<ans.size();i++){
            res += ans[i];
        }
        cout<<res<<endl;
        if(imp || res.size()<26){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
            cout<<res<<endl;
        }
    }

    return 0;
}


        /*----------------------------------*\
        ******BISMILLAHIR RAHMANIR RAHIM******
        ********************
        *****************
        /*************************************/

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define NL printf("\n")
#define xx first
#define yy second
#define gc getchar
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define scani(x) scanf("%d",&x)
#define scanl(x) scanf("%lld",&x)//scanf("%I64d",&x)
#define scand(x) scanf("%lf",&x)
#define scans(x) scanf("%s",x)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(i=j;i<=k;i++)
#define REV(i,j,k) for(i=j;i>=k;i--)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define cnd tree[idx]
#define lnd tree[idx*2]
#define rnd tree[(idx*2)+1]
#define lndp (idx*2),(b),((b+e)/2)
#define rndp (idx*2+1),((b+e)/2+1),(e)
#define pi 2.0*acos(0.0)
#define MOD 1000000007
#define MAX 100005
#define PRINT_CASE(x) printf("Case %d:",cs);

#define sc1(a)  scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define pi1(a) printf("%lld",a)
#define pi2(a,b) printf("%lld %lld",a,b)
#define pi3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define sp printf(" ")
#define yes printf("YES")
#define no printf("NO")

#define all(v) v.begin(),v.end()

template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b);while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BigMod(T A,T B,T M){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T InvMod (T A,T M){return BigMod(A,M-2,M);}
ll gcdr ( ll a, ll b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}
/*
ll poW(ll x, ll n)
{
    if(n==0)
        return 1;
    else if(n%2==0)
        return poW(x*x,n/2);
    else
        return x*poW(x*x,((n-1)/2));
}
*/
/*
int gcdr ( int a, int b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}

const int maxx=1000000;
int status[(maxx>>5)+2];

bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}
int Set(int N, int pos)
{
    return N=(N|(1<<pos));
}
vector<int>P_list;
void sieve()
{
    int i,j,sqrtN;
    sqrtN=int(sqrt(maxx))+1;
    P_list.push_back(2);
    for(int i=3;i<=maxx;i+=2)
    {
        if(check(status[i>>5],i&31)==0)
        {
            P_list.push_back(i);

            if(i<=sqrtN)
            for(j=i*i;j<=maxx;j+=(i<<1))
            {
                status[j>>5]=Set(status[j>>5],j & 31);
            }
        }
    }
}
*/
ll max(ll a,ll b){
    if(a>b) return a;
        return b;
}
ll min(ll a, ll b){
    if(a<b)return a;
            return b;
}
void FastIO()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.precision(20);
}
const ll size3=300005;
const ll size2=200005;
const ll size1=100005;
/*
void graph(ll n){
    if(n==0) return ;
    for(ll i=0;i<n;i++){
        ll x,y;
        sc2(x,y);
        G[x].pb(y);
        G[y].pb(x);
    }
    return ;
}
*/
set<ll> G[200];
ll visited[200] = {0};
string ss = "";
ll imp = 0;
void dfs(ll curr,ll last) {
    visited[curr] = 1;
    ss += (char)(curr + 'a');
    for(auto it = G[curr].begin(); it != G[curr].end();++it){
        if(visited[*it]==1){
            imp = 1;
            //cout<<curr<<" "<<*it<<endl;
            return ;
        }
        else if(*it!=last && visited[*it]==0)
        dfs(*it,curr);
    }
    return ;
}
int main()
{
    FastIO();
    ll t,i,j,m,x,y,n;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        imp = 0;
        mem(visited,0);
        n = s.size();
        for(i=0;i<199;i++){
            G[i].clear();
        }
        for(i=1;i<n;i++) {
            if(s[i]==s[i-1]){
                continue;
            }
            G[s[i]-'a'].insert(s[i-1]-'a');
            G[s[i-1]-'a'].insert(s[i]-'a');
        }
        vector<string > ans;
        for(i=0;i<26;i++){
            if(visited[i]==0 && G[i].size()==1){
                ss = "";
                dfs(i,i);
                ans.pb(ss);
            }
            else if(visited[i]==0 && G[i].size()==0){
                ss = "";
                ss += (char)(i+'a');
                ans.pb(ss);
            }
        }
        string res = "";
        for(i=0;i<ans.size();i++){
            res += ans[i];
        }
        //cout<<res<<endl;
        if(imp || res.size()<26){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
            cout<<res<<endl;
        }
    }

    return 0;
}


        /*----------------------------------*\
        ******BISMILLAHIR RAHMANIR RAHIM******
        ********************
        *****************
        /*************************************/

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define NL printf("\n")
#define xx first
#define yy second
#define gc getchar
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define scani(x) scanf("%d",&x)
#define scanl(x) scanf("%lld",&x)//scanf("%I64d",&x)
#define scand(x) scanf("%lf",&x)
#define scans(x) scanf("%s",x)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(i=j;i<=k;i++)
#define REV(i,j,k) for(i=j;i>=k;i--)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define cnd tree[idx]
#define lnd tree[idx*2]
#define rnd tree[(idx*2)+1]
#define lndp (idx*2),(b),((b+e)/2)
#define rndp (idx*2+1),((b+e)/2+1),(e)
#define pi 2.0*acos(0.0)
#define MOD 1000000007
#define MAX 100005
#define PRINT_CASE(x) printf("Case %d:",cs);

#define sc1(a)  scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define pi1(a) printf("%lld",a)
#define pi2(a,b) printf("%lld %lld",a,b)
#define pi3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define sp printf(" ")
#define yes printf("YES")
#define no printf("NO")

#define all(v) v.begin(),v.end()

template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b);while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BigMod(T A,T B,T M){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T InvMod (T A,T M){return BigMod(A,M-2,M);}
ll gcdr ( ll a, ll b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}
/*
ll poW(ll x, ll n)
{
    if(n==0)
        return 1;
    else if(n%2==0)
        return poW(x*x,n/2);
    else
        return x*poW(x*x,((n-1)/2));
}
*/
/*
int gcdr ( int a, int b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}

const int maxx=1000000;
int status[(maxx>>5)+2];

bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}
int Set(int N, int pos)
{
    return N=(N|(1<<pos));
}
vector<int>P_list;
void sieve()
{
    int i,j,sqrtN;
    sqrtN=int(sqrt(maxx))+1;
    P_list.push_back(2);
    for(int i=3;i<=maxx;i+=2)
    {
        if(check(status[i>>5],i&31)==0)
        {
            P_list.push_back(i);

            if(i<=sqrtN)
            for(j=i*i;j<=maxx;j+=(i<<1))
            {
                status[j>>5]=Set(status[j>>5],j & 31);
            }
        }
    }
}
*/
ll max(ll a,ll b){
    if(a>b) return a;
        return b;
}
ll min(ll a, ll b){
    if(a<b)return a;
            return b;
}
void FastIO()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.precision(20);
}
const ll size3=300005;
const ll size2=200005;
const ll size1=100005;
/*
void graph(ll n){
    if(n==0) return ;
    for(ll i=0;i<n;i++){
        ll x,y;
        sc2(x,y);
        G[x].pb(y);
        G[y].pb(x);
    }
    return ;
}
*/
set<ll> G[200];
ll visited[200] = {0};
string ss = "";
ll imp = 0;
void dfs(ll curr,ll last) {
    visited[curr] = 1;
    ss += (char)(curr + 'a');
    for(auto it = G[curr].begin(); it != G[curr].end();++it){
        if(visited[*it]==1 && *it!=last){
            imp = 1;
            //cout<<curr<<" "<<*it<<endl;
            return ;
        }
        else if(*it!=last && visited[*it]==0)
        dfs(*it,curr);
    }
    return ;
}
int main()
{
    FastIO();
    ll t,i,j,m,x,y,n;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        imp = 0;
        mem(visited,0);
        n = s.size();
        for(i=0;i<199;i++){
            G[i].clear();
        }
        for(i=1;i<n;i++) {
            if(s[i]==s[i-1]){
                continue;
            }
            G[s[i]-'a'].insert(s[i-1]-'a');
            G[s[i-1]-'a'].insert(s[i]-'a');
        }
        vector<string > ans;
        for(i=0;i<26;i++){
            if(visited[i]==0 && G[i].size()==1){
                ss = "";
                dfs(i,i);
                ans.pb(ss);
            }
            else if(visited[i]==0 && G[i].size()==0){
                ss = "";
                ss += (char)(i+'a');
                ans.pb(ss);
            }
        }
        string res = "";
        for(i=0;i<ans.size();i++){
            res += ans[i];
        }
        //cout<<res<<endl;
        if(imp || res.size()<26){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
            cout<<res<<endl;
        }
    }

    return 0;
}


        /*----------------------------------*\
        ******BISMILLAHIR RAHMANIR RAHIM******
        ********************
        *****************
        /*************************************/

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define NL printf("\n")
#define xx first
#define yy second
#define gc getchar
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define scani(x) scanf("%d",&x)
#define scanl(x) scanf("%lld",&x)//scanf("%I64d",&x)
#define scand(x) scanf("%lf",&x)
#define scans(x) scanf("%s",x)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(i=j;i<=k;i++)
#define REV(i,j,k) for(i=j;i>=k;i--)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define cnd tree[idx]
#define lnd tree[idx*2]
#define rnd tree[(idx*2)+1]
#define lndp (idx*2),(b),((b+e)/2)
#define rndp (idx*2+1),((b+e)/2+1),(e)
#define pi 2.0*acos(0.0)
#define MOD 1000000007
#define MAX 100005
#define PRINT_CASE(x) printf("Case %d:",cs);

#define sc1(a)  scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define pi1(a) printf("%lld",a)
#define pi2(a,b) printf("%lld %lld",a,b)
#define pi3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define sp printf(" ")
#define yes printf("YES")
#define no printf("NO")

#define all(v) v.begin(),v.end()

template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b);while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BigMod(T A,T B,T M){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T InvMod (T A,T M){return BigMod(A,M-2,M);}
ll gcdr ( ll a, ll b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}
/*
ll poW(ll x, ll n)
{
    if(n==0)
        return 1;
    else if(n%2==0)
        return poW(x*x,n/2);
    else
        return x*poW(x*x,((n-1)/2));
}
*/
/*
int gcdr ( int a, int b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}

const int maxx=1000000;
int status[(maxx>>5)+2];

bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}
int Set(int N, int pos)
{
    return N=(N|(1<<pos));
}
vector<int>P_list;
void sieve()
{
    int i,j,sqrtN;
    sqrtN=int(sqrt(maxx))+1;
    P_list.push_back(2);
    for(int i=3;i<=maxx;i+=2)
    {
        if(check(status[i>>5],i&31)==0)
        {
            P_list.push_back(i);

            if(i<=sqrtN)
            for(j=i*i;j<=maxx;j+=(i<<1))
            {
                status[j>>5]=Set(status[j>>5],j & 31);
            }
        }
    }
}
*/
ll max(ll a,ll b){
    if(a>b) return a;
        return b;
}
ll min(ll a, ll b){
    if(a<b)return a;
            return b;
}
void FastIO()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.precision(20);
}
const ll size3=300005;
const ll size2=200005;
const ll size1=100005;
/*
void graph(ll n){
    if(n==0) return ;
    for(ll i=0;i<n;i++){
        ll x,y;
        sc2(x,y);
        G[x].pb(y);
        G[y].pb(x);
    }
    return ;
}
*/
set<ll> G[200];
ll visited[200] = {0};
string ss = "";
ll imp = 0;
void dfs(ll curr,ll last) {
    visited[curr] = 1;
    ss += (char)(curr + 'a');
    for(auto it = G[curr].begin(); it != G[curr].end();++it){
        if(visited[*it]==1 && *it!=last){
            imp = 1;
            return ;
        }
        else if(*it!=last)
        dfs(*it,curr);
    }
    return ;
}
int main()
{
    FastIO();
    ll t,i,j,m,x,y,n;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        mem(visited,0);
        n = s.size();
        for(i=0;i<199;i++){
            G[i].clear();
        }
        for(i=1;i<n;i++) {
            G[s[i]-'a'].insert(s[i-1]-'a');
            G[s[i-1]-'a'].insert(s[i]-'a');
        }
        vector<string > ans;
        for(i=0;i<26;i++){
            if(visited[i]==0 && G[i].size()==1){
                ss = "";
                dfs(i,i);
                ans.pb(ss);
            }
            else if(visited[i]==0 && G[i].size()==0){
                ss = "";
                ss += (char)(i+'a');
                ans.pb(ss);
            }
        }
        string res = "";
        for(i=0;i<ans.size();i++){
            res += ans[i];
        }
        //cout<<res<<endl;
        if(imp || res.size()<26){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
            cout<<res<<endl;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;

vector<char> ad[28];
bool visit[28];

string BFS(char par,char last,int mark)
{

    visit[last-'a']=true;
    int p=last-'a';

    if(ad[p].size()==0) return "";

    else if(ad[p].size()==1) {
        if(ad[p][0]==par) return "";
        if(visit[ad[p][0]-'a']==true) return "-1";

        string x=BFS(last,ad[p][0],mark);
        if(x=="-1") return "-1";
        else{
            if(mark==0) x=string(1,ad[p][0])+x;
            else x=x+string(1,ad[p][0]);
            return x;
        }
    }

    if(ad[p][0]!=par &&  ad[p][1] != par)  return "-1";
    else{
        ll ch=(ad[p][0]==par) ? ad[p][1] : ad[p][0];
        if(visit[ch-'a']==true) return "-1";

        string x=BFS(last,ch,mark);
        if(x=="-1") return "-1";
        else{
            if(mark==0) x=string(1,ch)+x;
            else x=x+string(1,ch);
            return x;
        }
    }
}

int main()
{
    Go_
    int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;

    cin>>t;
    while(t--)
    {
        cin>>str;
        int len=str.length();
        for(i=0;i<26;i++) ad[i].clear();

        for(i=0;i<len;i++){
            int p=str[i]-'a';
            if(i+1<len){
                bl=false;
                for(auto xx: ad[p]) {
                    if(xx == str[i+1]);
                    bl=true;
                    break;
                }
                if(!bl) ad[p].push_back(str[i+1]);
            }
            else if(i-1>=0){
                bl=false;
                for(auto xx: ad[p]) {
                    if(xx == str[i-1]);
                    bl=true;
                    break;
                }
                if(!bl) ad[p].push_back(str[i-1]);
            }
        }

        bl=true;
        for(i=0;i<26;i++){
            if(ad[i].size()>2){
                bl=false;
                break;
            }
        }

        if(!bl) cout<<"NO"<<endl;
        else{

            bl=false;
            string ans="";
            for(i=0;i<26;i++){
                string left="",right="";
                int siz=ad[i].size();

                if(siz==0) continue;
                memset(visit,false,sizeof visit);
                visit[i]=true;

                if(siz>0) right=BFS('a'+i,ad[i][0],0);
                if(siz>1) left=BFS('a'+i,ad[i][1],1);

                if(right != "-1" && left != "-1"){
                    ans=left;
                    if(siz>1) ans+=string(1,ad[i][1]);
                    ans+=string(1,'a'+i);
                    ans+=string(1,ad[i][0]);
                    ans+=right;
                    bl=true;
                    break;
                }
            }

            //cout<<"OK"<<endl;

            if(bl==false) cout<<"NO"<<endl;
            else{
                int len=ans.length();
                for(i=0;i<26;i++){
                    bl=false;
                    for(j=0;j<len;j++){
                        if(ans[j]==('a'+i)) {
                            bl=true;
                            break;
                        }
                    }
                    if(!bl) ans+=string(1,'a'+i);
                }

                cout<<"YES"<<endl;
                cout<<ans<<endl;

            }
        }
    }

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=28;

vector<char> ad[sz];
bool visit[sz];

string fun(char last)
{
    string str=string(1,last);
    int i=0;
    visit[last-'a']=true;
    while(true){
        int p=str[i]-'a';
        if(ad[p].size()==0) break;
        if(ad[p].size()>2) return "-1";

        if(ad[p].size()==1){
            int x=ad[p][0]-'a';
            if(visit[x]){
                if(i-1>=0 && str[i-1]==(x+'a')) return str;
                else return "-1";
            }
            else{
                str+=string(1,'a'+x);
                ++i,visit[x]=true;
            }
        }

        else if(ad[p].size()==2){
            if(i-1>=0 && ((ad[p][0] != str[i-1]) && (ad[p][1] != str[i-1]))) return "-1";
            char ch=(ad[p][0]==str[i-1]) ? ad[p][1] : ad[p][0];
            int x=ch-'a';

            if(visit[x]) return "-1";
            str+=string(1,'a'+x);
            ++i,visit[x]=true;
        }

        else return "-1";
    }

    return str;
}
int main()
{
    Go_
    int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;

    cin>>t;
    while(t--)
    {
        cin>>str;
        for(i=0;i<sz;i++) ad[i].clear();
        int len=str.length();

        for(i=0;i<len-1;i++){
            p=str[i]-'a';
            bl=false;
            for(auto xx : ad[p]){
                if(xx==str[i+1]){
                    bl=true;
                    break;
                }
            }
            if(!bl) ad[p].push_back(str[i+1]);
        }

        string  ans="-1";
        for(i=0;i<26;i++){
            if(ad[i].size()==1){
                memset(visit,false,sizeof visit);

                string kick=fun('a'+i);
                if(kick != "-1") {
                    ans=kick;
                    break;
                }
            }

            if(ans != "-1") break;
        }

        if(ans=="-1" && len>1) cout<<"NO"<<endl;
        else{
            int len=ans.size();
            if(ans=="-1") ans="";
            for(i=0;i<26;i++){
                bl=false;
                for(j=0;j<len;j++){
                    if(ans[j]==('a'+i)){
                        bl=true;
                        break;
                    }
                }

                if(!bl) ans+=('a'+i);
            }

            cout<<"YES"<<endl;
            cout<<ans<<endl;
        }
    }

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=28;

vector<char> ad[sz],back[sz];
bool visit[sz];

string fun(char last)
{
    string str=string(1,last);
    int i=0;
    visit[last-'a']=true;
    while(true){
        int p=str[i]-'a';
        if(ad[p].size()==0) break;
        if(ad[p].size()>2) return "-1";

        if(ad[p].size()==1){
            int x=ad[p][0]-'a';
            if(visit[x]){
                if(i-1>=0 && str[i-1]==(x+'a')) return str;
                else return "-1";
            }
            else{
                str+=string(1,'a'+x);
                ++i,visit[x]=true;
            }
        }

        else if(ad[p].size()==2){
            if(i-1>=0 && ((ad[p][0] != str[i-1]) && (ad[p][1] != str[i-1]))) return "-1";
            char ch=(ad[p][0]==str[i-1]) ? ad[p][1] : ad[p][0];
            int x=ch-'a';

            if(visit[x]) return "-1";
            str+=string(1,'a'+x);
            ++i,visit[x]=true;
        }

        else return "-1";
    }

    return str;
}
int main()
{
    Go_
    int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;

    cin>>t;
    while(t--)
    {
        cin>>str;
        for(i=0;i<sz;i++) ad[i].clear(),back[i].clear();
        int len=str.length();

        for(i=0;i<len-1;i++){
            p=str[i]-'a';
            bl=false;
            for(auto xx : ad[p]){
                if(xx==str[i+1]){
                    bl=true;
                    break;
                }
            }
            if(!bl) ad[p].push_back(str[i+1]);

            p=str[i+1]-'a';
            bl=false;
            for(auto xx : ad[p]){
                if(xx==str[i]){
                    bl=true;
                    break;
                }
            }
            if(!bl) back[p].push_back(str[i]);

        }

        string  ans="-1";
        for(i=0;i<26;i++){
            if(ad[i].size()==1 && (back[i].size()==0 || (back[i].size()==1 && back[i][0]==ad[i][0]))){
                memset(visit,false,sizeof visit);

                string kick=fun('a'+i);
                if(kick != "-1") {
                    ans=kick;
                    break;
                }
            }

            if(ans != "-1") break;
        }

        if(ans=="-1" && len>1) cout<<"NO"<<endl;
        else{
            int len=ans.size();
            if(ans=="-1") ans="";
            for(i=0;i<26;i++){
                bl=false;
                for(j=0;j<len;j++){
                    if(ans[j]==('a'+i)){
                        bl=true;
                        break;
                    }
                }

                if(!bl) ans+=('a'+i);
            }

            cout<<"YES"<<endl;
            cout<<ans<<endl;
        }
    }

}