#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";
        if(ad[p][0] != par && visit[ad[p][0]]==true) return "-1";
        if(ad[p][1] != par && visit[ad[p][1]]==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;
        }
    }

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

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

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

        if(ans=="-1") cout<<"NO"<<endl;
        else{
            int len=ans.size();
            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];
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;
        }
    }

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

                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(),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]);

            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;
        }
    }

}


#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;

struct node
{
    char left,right;
};
bool visit[27];

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;
        node ara[27];
        for(i=0;i<26;i++) ara[i].left='#',ara[i].right='#';
        memset(visit,false,sizeof visit);

        int len=str.length();
        bool bl=true;
        string ans="";
        ans+=string(1,str[0]),visit[str[0]-'a']=true;
        if(len>1) ara[str[0]-'a'].right=str[1];

        for(i=1;i<len;i++){
             p=str[i]-'a';
             if(visit[p]){
                 int x=str[i-1]-'a';
                 if(ara[x].right != str[i] && ara[x].left!=str[i]) bl=false;
             }
             else{
                 int siz=ans.size();
                 int x=str[i-1]-'a';
                 visit[p]=true;
                 if(ans[0]==str[i-1]){
                     ara[x].left=str[i];
                     ara[p].right=ans[0];
                     ans=string(1,str[i])+ans;
                 }
                 else if(ans[siz-1]==str[i-1]){
                     ara[x].right=str[i];
                     ara[p].left=str[i-1];
                     ans+=string(1,str[i]);
                 }
                 else bl=false;
             }
             if(!bl) break;
        }

        if(!bl)  cout<<"NO"<<endl;
        else{
            int siz=ans.size();
            for(i=0;i<26;i++){
                bool bl=false;

                for(j=0;j<siz;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 false);

                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;
        }
    }

}


// Problem : C. Perfect Keyboard
// Contest : Educational Codeforces Round 82 (Rated for Div. 2)
// URL : https://codeforces.com/problemset/problem/1303/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Author - Sumit

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

#define ll long long
#define int ll
#define ps push
#define pb insert
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }

string alp = "abcdefghijklmnopqrstuvwxyz";

const int N=205;
map<char,set<char>> v;
map<char,int> vis;

bool cycle=false;

string res="";
void dfs(char ch,char p){
	res+=ch;
	vis[ch]=1;
	for(auto x:v[ch]){
		if(vis[x]==1 && p!=x){
			cycle=true;
		}
		if(vis[x]==0){
			dfs(x,ch);
		}

	}
}

void solve(){
	rep(i,0,N) v[i].clear();
	vis.clear();
	string s;
	cin>>s;
	int n=s.size();
	rep(i,0,n){
		if(i-1>=0) v[s[i]].pb(s[i-1]),v[s[i-1]].pb(s[i]);
		if(i+1<n) v[s[i]].pb(s[i+1]),v[s[i+1]].pb(s[i]);
	}
	char xx='1';
	rep(i,0,n){
		if(vis[s[i]]==0){
			dfs(s[i],xx);
			break;
		}

	}
	// debug(res);
	if(cycle){
		debug("NO");
	}else{
		debug("YES");
		int sz=res.size();
		char node = res[sz-1];
		res="";
		vis.clear();
		dfs(node,xx);
		set<int> st;
		rep(i,0,sz) cout<<res[i];
		rep(i,0,26){
			if(vis[alp[i]]==0) cout<<alp[i];
		}
		// debug(res);
		cout<<"\n";
	}
    res="";
	cycle=false;

}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


// Problem : C. Perfect Keyboard
// Contest : Educational Codeforces Round 82 (Rated for Div. 2)
// URL : https://codeforces.com/problemset/problem/1303/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Author - Sumit

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

#define ll long long
#define int ll
#define ps push
#define pb insert
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }

string alp = "abcdefghijklmnopqrstuvwxyz";

const int N=205;
map<char,set<char>> v;
map<char,int> vis;

bool cycle=false;

string res="";
void dfs(char ch,char p){
	res+=ch;
	vis[ch]=1;
	for(auto x:v[ch]){
		if(vis[x]==1 && p!=x){
			cycle=true;
		}
		if(vis[x]==0){
			dfs(x,ch);
		}

	}
}

void solve(){
	rep(i,0,N) v[i].clear();
	vis.clear();
	string s;
	cin>>s;
	int n=s.size();
	rep(i,0,n){
		if(i-1>=0) v[s[i]].pb(s[i-1]),v[s[i-1]].pb(s[i]);
		if(i+1<n) v[s[i]].pb(s[i+1]),v[s[i+1]].pb(s[i]);
	}
	char xx='1';
	rep(i,0,n){
		if(vis[s[i]]==0){
			dfs(s[i],xx);
			break;
		}

	}
	// debug(res);
	if(cycle){
		debug("NO");
	}else{
		debug("YES");
		int sz=res.size();
		char node = res[sz-1];
		res="";
		vis.clear();
		dfs(node,xx);
		set<int> st;
		rep(i,0,sz) st.insert(res[i]);
		rep(i,0,26){
			if(vis[alp[i]]==0) cout<<alp[i];
		}
		debug(res);
	}
    res="";
		cycle=false;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


// Problem : C. Perfect Keyboard
// Contest : Educational Codeforces Round 82 (Rated for Div. 2)
// URL : https://codeforces.com/problemset/problem/1303/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Author - Sumit

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

#define ll long long
#define int ll
#define ps push
#define pb insert
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }

string alp = "abcdefghijklmnopqrstuvwxyz";

const int N=205;
map<char,set<char>> v;
map<char,int> vis;

bool cycle=false;

string res="";
void dfs(char ch,char p){
	res+=ch;
	vis[ch]=1;
	for(auto x:v[ch]){
		if(vis[x]==1 && p!=x){
			cycle=true;
		}
		if(vis[x]==0){
			dfs(x,ch);
		}

	}
}

void solve(){
	rep(i,0,N) v[i].clear();
	vis.clear();
	string s;
	cin>>s;
	int n=s.size();
	rep(i,0,n){
		if(i-1>=0) v[s[i]].pb(s[i-1]),v[s[i-1]].pb(s[i]);
		if(i+1<n) v[s[i]].pb(s[i+1]),v[s[i+1]].pb(s[i]);
	}
	char xx='1';
	rep(i,0,n){
		if(vis[s[i]]==0){
			dfs(s[i],xx);
			break;
		}

	}
	// debug(res);
	rep(i,0,26){
		if(v[char(i+'a')].size()>2) cycle=true;
	}
	if(cycle){
		debug("NO");
	}else{
		debug("YES");
		int sz=res.size();
		char node = res[sz-1];
		res="";
		vis.clear();
		dfs(node,xx);
		set<int> st;
		rep(i,0,sz) st.insert(res[i]);
		reverse(all(res));
		rep(i,0,26){
			if(st.find(alp[i])==st.end()) res+=alp[i],st.pb(alp[i]);
		}
		debug(res);
	}
    res="";
	cycle=false;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


// Problem : C. Perfect Keyboard
// Contest : Educational Codeforces Round 82 (Rated for Div. 2)
// URL : https://codeforces.com/problemset/problem/1303/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Author - Sumit

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

#define ll long long
#define int ll
#define ps push
#define pb emplace_back
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }

string alp = "abcdefghijklmnopqrstuvwxyz";

set<int> v[26];
map<char,int> vis;

bool cycle=false;

vi res;
void dfs(int ch,int p){
	res.pb(ch);
	vis[ch]=1;
	for(auto x:v[ch]){
		if(vis[x]==1 && p!=x){
			cycle=true;
		}
		if(vis[x]==0){
			dfs(x,ch);
		}
	}
}

void solve(){
	rep(i,0,26) v[i].clear();
	vis.clear();
	string s;
	cin>>s;
	int n=s.size();
	rep(i,0,n-1){
		v[s[i]-'a'].insert(s[i+1]-'a');
        v[s[i+1]-'a'].insert(s[i]-'a');
	}
	int xx=-1;
	rep(i,0,n){
		if(vis[s[i]-'a']==0){
			dfs(s[i]-'a',xx);
			break;
		}

	}
	// debug(res);
	rep(i,0,26){
		if(v[i].size()>2) cycle=true;
	}
	if(cycle){
		debug("NO");
	}else{
		debug("YES");
		res.clear();
		vis.clear();
		rep(i,0,26){
			if(v[i].size()==1){
				dfs(i,xx);
				break;
			}
		}
		int sz=res.size();
		reverse(all(res));
		rep(i,0,sz) cout<<char(res[i]+'a');
		rep(i,0,26) if(!vis[i]) cout<<char(i+'a');
		cout<<"\n";
	}
    res.clear();
    cycle=false;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


// Problem : C. Perfect Keyboard
// Contest : Educational Codeforces Round 82 (Rated for Div. 2)
// URL : https://codeforces.com/problemset/problem/1303/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Author - Sumit

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

#define ll long long
#define int ll
#define ps push
#define pb insert
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }

string alp = "abcdefghijklmnopqrstuvwxyz";

const int N=205;
map<char,set<char>> v;
map<char,int> vis;

bool cycle=false;

string res="";
void dfs(char ch,char p){
	res+=ch;
	vis[ch]=1;
	for(auto x:v[ch]){
		if(vis[x]==1 && p!=x){
			cycle=true;
		}
		if(vis[x]==0){
			dfs(x,ch);
		}

	}
}

void solve(){
	rep(i,0,N) v[i].clear();
	vis.clear();
	string s;
	cin>>s;
	int n=s.size();
	rep(i,0,n){
		if(i-1>=0) v[s[i]].pb(s[i-1]),v[s[i-1]].pb(s[i]);
		if(i+1<n) v[s[i]].pb(s[i+1]),v[s[i+1]].pb(s[i]);
	}
	char xx='1';
	rep(i,0,n){
		if(vis[s[i]]==0){
			dfs(s[i],xx);
			break;
		}

	}
	// debug(res);
	if(cycle){
		debug("NO");
	}else{
		debug("YES");
		int sz=res.size();
		char node = res[sz-1];
		res="";
		vis.clear();
		dfs(node,xx);
		set<int> st;
		rep(i,0,sz) st.insert(res[i]);
		rep(i,0,26){
			if(st.find(alp[i])==st.end()) res+=alp[i],st.pb(alp[i]);
		}
		debug(res);
	}
    res="";
	cycle=false;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


// Problem : C. Perfect Keyboard
// Contest : Educational Codeforces Round 82 (Rated for Div. 2)
// URL : https://codeforces.com/problemset/problem/1303/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Author - Sumit

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

#define ll long long
#define int ll
#define ps push
#define pb emplace_back
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }

string alp = "abcdefghijklmnopqrstuvwxyz";

set<int> v[26];
map<char,int> vis;

bool cycle=false;

vi res;
void dfs(int ch,int p){
	res.pb(ch);
	vis[ch]=1;
	for(auto x:v[ch]){
		if(vis[x]==1 && p!=x){
			cycle=true;
		}
		if(vis[x]==0){
			dfs(x,ch);
		}
	}
}

void solve(){
	rep(i,0,26) v[i].clear();
	vis.clear();
	string s;
	cin>>s;
	int n=s.size();
	rep(i,0,n-1){
		v[s[i]-'a'].insert(s[i+1]-'a');
        v[s[i+1]-'a'].insert(s[i]-'a');
	}
	int xx=-1;
	rep(i,0,n){
		if(vis[s[i]-'a']==0){
			dfs(s[i]-'a',xx);
			break;
		}

	}
	// debug(res);
	if(cycle){
		debug("NO");
	}else{
		debug("YES");
		res.clear();
		vis.clear();
		rep(i,0,26){
			if(v[i].size()==1){
				dfs(i,xx);
				break;
			}
		}
		int sz=res.size();
		reverse(all(res));
		rep(i,0,sz) cout<<char(res[i]+'a');
		rep(i,0,26) if(!vis[i]) cout<<char(i+'a');
		cout<<"\n";
	}
    res.clear();
    cycle=false;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


// Problem : C. Perfect Keyboard
// Contest : Educational Codeforces Round 82 (Rated for Div. 2)
// URL : https://codeforces.com/problemset/problem/1303/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Author - Sumit

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

#define ll long long
#define int ll
#define ps push
#define pb insert
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }

string alp = "abcdefghijklmnopqrstuvwxyz";

const int N=205;
map<char,set<char>> v;
map<char,int> vis;

bool cycle=false;

string res="";
void dfs(char ch,char p){
	res+=ch;
	vis[ch]=1;
	for(auto x:v[ch]){
		if(vis[x]==1 && p!=x){
			cycle=true;
		}
		if(vis[x]==0){
			dfs(x,ch);
		}

	}
}

void solve(){
	rep(i,0,N) v[i].clear();
	vis.clear();
	string s;
	cin>>s;
	int n=s.size();
	rep(i,0,n){
		if(i-1>=0) v[s[i]].pb(s[i-1]);
		if(i+1<n) v[s[i]].pb(s[i+1]);
	}
	char xx='1';
	rep(i,0,n){
		if(vis[s[i]]==0){
			dfs(s[i],xx);
			break;
		}

	}
	// debug(res);
	if(cycle){
		debug("NO");
	}else{
		debug("YES");
		int sz=res.size();
		char node = res[sz-1];
		res="";
		vis.clear();
		dfs(node,xx);
		set<int> st;
		rep(i,0,sz) st.insert(res[i]);
		rep(i,0,26){
			if(vis[alp[i]]==0) cout<<alp[i];
		}
		debug(res);
	}
    res="";
	cycle=false;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


// Problem : C. Perfect Keyboard
// Contest : Educational Codeforces Round 82 (Rated for Div. 2)
// URL : https://codeforces.com/problemset/problem/1303/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Author - Sumit

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

#define ll long long
#define int ll
#define ps push
#define pb insert
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }

string alp = "abcdefghijklmnopqrstuvwxyz";

const int N=500;
map<char,set<char>> v;
map<char,int> vis;

bool cycle=false;

string res="";
void dfs(char ch,char p){
	res+=ch;
	vis[ch]=1;
	for(auto x:v[ch]){
		if(vis[x]==1 && p!=x){
			cycle=true;
		}
		if(vis[x]==0){
			dfs(x,ch);
		}

	}
}

void solve(){
	rep(i,0,N) v[i].clear();
	vis.clear();
	string s;
	cin>>s;
	int n=s.size();
	rep(i,0,n){
		if(i-1>=0) v[s[i]].pb(s[i-1]);
		if(i+1<n) v[s[i]].pb(s[i+1]);
	}
	char xx='1';
	rep(i,0,n){
		if(vis[s[i]]==0){
			dfs(s[i],xx);
			break;
		}

	}
	// debug(res);
	if(cycle){
		debug("NO");
	}else{
		debug("YES");
		int sz=res.size();
		char node = res[sz-1];
		res="";
		vis.clear();
		dfs(node,xx);
		set<int> st;
		rep(i,0,sz) st.insert(res[i]);
		rep(i,0,26){
			if(vis[alp[i]]==0) cout<<alp[i];
		}
		debug(res);
	}
    res="";
    cycle=false;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T, typename F>
void chmax( T &a, F b) {
  if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
  if (b < a)a = b;
}

/* if you want to multiply 2 64 bit numbers mod c.
 i.e a*b%c.
 this function will help  in preventing "overflow".
*/

ll mulmod(ll a, ll b, ll c) {

  ll ans = 0;
  ll y = a % c;
  while (b) {
    if (b & 1) {
      (ans += y) %= c;
    }
    y = y * 2 % c;
    b >>= 1;
  }
  return ans;

}

ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    //ans = mulmod(ans, a, m);
    a = a * a % m;
    //a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll powMbig(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)//ans = ans * a % m;
      ans = mulmod(ans, a, m);
    //a = a * a % m;
    a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll poww(ll a, ll b)
{

  ll ans = 1;
  while (b)
  {
    if (b & 1)ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;

}

string tostring(ll x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}

const ll N = 1e6 + 5;

vector<set<ll>>arr(30);
vl vis(30);

ll flag = 0;

void dfs1(ll node, ll par) {
  if (flag)return;
  vis[node] = 1;
  for (auto d : arr[node]) {
    if (d == par)continue;
    if (vis[d]) {
      flag = 1;
      return;
    }
    else dfs1(d, node);
  }
}

vl ans;

void dfs2(ll node, ll par) {
  ans.pb(node);
  vis[node] = 1;
  for (auto d : arr[node]) {
    if (!vis[d]) {

      dfs2(d, node);
    }
  }
}

int main() {

  IOS;

#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif

  ll t; cin >> t;
  while (t--) {
    string s; cin >> s;
    FOR(i, 30)arr[i].clear(), vis[i] = 0;
    ll n = sz(s);
    ans.clear();
    flag = 0;
    for (ll i = 1; i < n; i++) {
      ll a1 = s[i - 1] - 'a';
      ll a2 = s[i] - 'a';
      arr[a1].insert(a2);
      arr[a2].insert(a1);
    }
    FOR(i, 26) {
      if (sz(arr[i]) > 2) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      d1("NO");
      continue;
    }

    dfs1(0, -1);

    if (flag) {
      d1("NO");
      continue;
    }

    FOR(i, 30)vis[i] = 0;

    //  ans.clear();

    for (ll  i = 0; i < 26; i++) {
      if (sz(arr[i]) == 1) {
        dfs2(i, -1);
        break;
      }
    }

    for (ll i = 0; i < 26; i++) {
      if (!vis[i])ans.pb(i);
    }

    d1("YES");
    assert(sz(ans) == 26);
    for (auto d : ans) {
      cout << char(d + 'a');
    }
    cout << endl;

  }

  return 0;
}


//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T, typename F>
void chmax( T &a, F b) {
  if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
  if (b < a)a = b;
}

/* if you want to multiply 2 64 bit numbers mod c.
 i.e a*b%c.
 this function will help  in preventing "overflow".
*/

ll mulmod(ll a, ll b, ll c) {

  ll ans = 0;
  ll y = a % c;
  while (b) {
    if (b & 1) {
      (ans += y) %= c;
    }
    y = y * 2 % c;
    b >>= 1;
  }
  return ans;

}

ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    //ans = mulmod(ans, a, m);
    a = a * a % m;
    //a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll powMbig(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)//ans = ans * a % m;
      ans = mulmod(ans, a, m);
    //a = a * a % m;
    a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll poww(ll a, ll b)
{

  ll ans = 1;
  while (b)
  {
    if (b & 1)ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;

}

string tostring(ll x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}

const ll N = 1e6 + 5;

vector<set<ll>>arr(30);
vl vis(30);

ll flag = 0;

void dfs1(ll node, ll par) {
  //if (flag)return;
  vis[node] = 1;
  for (auto d : arr[node]) {
    // if (flag)return;
    if (d == par)continue;
    if (vis[d]) {
      flag = 1;
      // return;
    }
    else dfs1(d, node);
  }
}

vl ans;

void dfs2(ll node, ll par) {
  ans.pb(node);
  vis[node] = 1;
  for (auto d : arr[node]) {
    if (!vis[d]) {

      dfs2(d, node);
    }
  }
}

int main() {

  IOS;

#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif

  ll t; cin >> t;
  while (t--) {
    string s; cin >> s;
    FOR(i, 30)arr[i].clear(), vis[i] = 0;
    ll n = sz(s);
    ans.clear();
    flag = 0;
    for (ll i = 1; i < n; i++) {
      ll a1 = s[i - 1] - 'a';
      ll a2 = s[i] - 'a';
      if (a1 == a2)flag = 1;
      arr[a1].insert(a2);
      arr[a2].insert(a1);
    }
    FOR(i, 26) {
      if (sz(arr[i]) > 2) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      d1("NO");
      continue;
    }

    dfs1(0, -1);

    if (flag) {
      d1("NO");
      continue;
    }

    FOR(i, 30)vis[i] = 0;

    //  ans.clear();

    for (ll  i = 0; i < 26; i++) {
      if (sz(arr[i]) == 1) {
        dfs2(i, -1);
        break;
      }
    }

    for (ll i = 0; i < 26; i++) {
      if (!vis[i])ans.pb(i);
    }

    d1("YES");
    assert(sz(ans) == 26);
    for (auto d : ans) {
      cout << char(d + 'a');
    }
    cout << endl;

  }

  return 0;
}


//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T, typename F>
void chmax( T &a, F b) {
  if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
  if (b < a)a = b;
}

/* if you want to multiply 2 64 bit numbers mod c.
 i.e a*b%c.
 this function will help  in preventing "overflow".
*/

ll mulmod(ll a, ll b, ll c) {

  ll ans = 0;
  ll y = a % c;
  while (b) {
    if (b & 1) {
      (ans += y) %= c;
    }
    y = y * 2 % c;
    b >>= 1;
  }
  return ans;

}

ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    //ans = mulmod(ans, a, m);
    a = a * a % m;
    //a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll powMbig(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)//ans = ans * a % m;
      ans = mulmod(ans, a, m);
    //a = a * a % m;
    a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll poww(ll a, ll b)
{

  ll ans = 1;
  while (b)
  {
    if (b & 1)ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;

}

string tostring(ll x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}

const ll N = 1e6 + 5;

vector<set<ll>>arr(30);
vl vis(30);

ll flag = 0;

void dfs1(ll node, ll par) {
  if (flag)return;
  vis[node] = 1;
  for (auto d : arr[node]) {
    if(flag)return;
    if (d == par)continue;
    if (vis[d]) {
      flag = 1;
      return;
    }
    else dfs1(d, node);
  }
}

vl ans;

void dfs2(ll node, ll par) {
  ans.pb(node);
  vis[node] = 1;
  for (auto d : arr[node]) {
    if (!vis[d]) {

      dfs2(d, node);
    }
  }
}

int main() {

  IOS;

#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif

  ll t; cin >> t;
  while (t--) {
    string s; cin >> s;
    FOR(i, 30)arr[i].clear(), vis[i] = 0;
    ll n = sz(s);
    ans.clear();
    flag = 0;
    for (ll i = 1; i < n; i++) {
      ll a1 = s[i - 1] - 'a';
      ll a2 = s[i] - 'a';
      if (a1 == a2)flag = 1;
      arr[a1].insert(a2);
      arr[a2].insert(a1);
    }
    FOR(i, 26) {
      if (sz(arr[i]) > 2) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      d1("NO");
      continue;
    }

    dfs1(0, -1);

    if (flag) {
      d1("NO");
      continue;
    }

    FOR(i, 30)vis[i] = 0;

    //  ans.clear();

    for (ll  i = 0; i < 26; i++) {
      if (sz(arr[i]) == 1) {
        dfs2(i, -1);
        break;
      }
    }

    for (ll i = 0; i < 26; i++) {
      if (!vis[i])ans.pb(i);
    }

    d1("YES");
    assert(sz(ans) == 26);
    for (auto d : ans) {
      cout << char(d + 'a');
    }
    cout << endl;

  }

  return 0;
}


//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T, typename F>
void chmax( T &a, F b) {
  if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
  if (b < a)a = b;
}

/* if you want to multiply 2 64 bit numbers mod c.
 i.e a*b%c.
 this function will help  in preventing "overflow".
*/

ll mulmod(ll a, ll b, ll c) {

  ll ans = 0;
  ll y = a % c;
  while (b) {
    if (b & 1) {
      (ans += y) %= c;
    }
    y = y * 2 % c;
    b >>= 1;
  }
  return ans;

}

ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    //ans = mulmod(ans, a, m);
    a = a * a % m;
    //a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll powMbig(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)//ans = ans * a % m;
      ans = mulmod(ans, a, m);
    //a = a * a % m;
    a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll poww(ll a, ll b)
{

  ll ans = 1;
  while (b)
  {
    if (b & 1)ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;

}

string tostring(ll x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}

const ll N = 1e6 + 5;

vector<set<ll>>arr(30);
vl vis(30);

ll flag = 0;

void dfs1(ll node, ll par) {
  if (flag)return;
  vis[node] = 1;
  for (auto d : arr[node]) {
    if (d == par)continue;
    if (vis[d]) {
      flag = 1;
      return;
    }
    else dfs1(d, node);
  }
}

vl ans;

void dfs2(ll node, ll par) {
  ans.pb(node);
  vis[node] = 1;
  for (auto d : arr[node]) {
    if (d != par) {

      dfs2(d, node);
    }
  }
}

int main() {

  IOS;

#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif

  ll t; cin >> t;
  while (t--) {
    string s; cin >> s;
    FOR(i, 30)arr[i].clear(), vis[i] = 0;
    ll n = sz(s);
    flag = 0;
    for (ll i = 1; i < n; i++) {
      ll a1 = s[i - 1] - 'a';
      ll a2 = s[i] - 'a';
      arr[a1].insert(a2);
      arr[a2].insert(a1);
    }
    FOR(i, 26) {
      if (sz(arr[i]) > 2) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      d1("NO");
      continue;
    }

    dfs1(0, -1);

    if (flag) {
      d1("NO");
      continue;
    }

    FOR(i, 30)vis[i] = 0;

    ans.clear();

    for (ll  i = 0; i < 26; i++) {
      if (!vis[i])dfs2(i, -1);
    }
    d1("YES");
    assert(sz(ans) == 26);
    for (auto d : ans) {
      cout << char(d + 'a');
    }
    cout << endl;

  }

  return 0;
}


//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T, typename F>
void chmax( T &a, F b) {
  if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
  if (b < a)a = b;
}

/* if you want to multiply 2 64 bit numbers mod c.
 i.e a*b%c.
 this function will help  in preventing "overflow".
*/

ll mulmod(ll a, ll b, ll c) {

  ll ans = 0;
  ll y = a % c;
  while (b) {
    if (b & 1) {
      (ans += y) %= c;
    }
    y = y * 2 % c;
    b >>= 1;
  }
  return ans;

}

ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    //ans = mulmod(ans, a, m);
    a = a * a % m;
    //a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll powMbig(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)//ans = ans * a % m;
      ans = mulmod(ans, a, m);
    //a = a * a % m;
    a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll poww(ll a, ll b)
{

  ll ans = 1;
  while (b)
  {
    if (b & 1)ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;

}

string tostring(ll x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}

const ll N = 1e6 + 5;

vector<set<ll>>arr(30);
vl vis(30);

ll flag = 0;

void dfs1(ll node, ll par) {
  if (flag)return;
  vis[node] = 1;
  for (auto d : arr[node]) {
    if (d == par)continue;
    if (vis[d]) {
      flag = 1;
      return;
    }
    else dfs1(d, node);
  }
}

vl ans;

void dfs2(ll node, ll par) {
  ans.pb(node);
  vis[node] = 1;
  for (auto d : arr[node]) {
    if (!vis[d]) {

      dfs2(d, node);
    }
  }
}

int main() {

  IOS;

#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif

  ll t; cin >> t;
  while (t--) {
    string s; cin >> s;
    FOR(i, 30)arr[i].clear(), vis[i] = 0;
    ll n = sz(s);
    ans.clear();
    flag = 0;
    for (ll i = 1; i < n; i++) {
      ll a1 = s[i - 1] - 'a';
      ll a2 = s[i] - 'a';
      arr[a1].insert(a2);
      arr[a2].insert(a1);
    }
    FOR(i, 26) {
      if (sz(arr[i]) > 2) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      d1("NO");
      continue;
    }

    dfs1(0, -1);

    if (flag) {
      d1("NO");
      continue;
    }

    FOR(i, 30)vis[i] = 0;

    //  ans.clear();

    for (ll  i = 0; i < 26; i++) {
      if (!vis[i])dfs2(i, -1);
    }
    d1("YES");
    assert(sz(ans) == 26);
    for (auto d : ans) {
      cout << char(d + 'a');
    }
    cout << endl;

  }

  return 0;
}


//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T, typename F>
void chmax( T &a, F b) {
  if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
  if (b < a)a = b;
}

/* if you want to multiply 2 64 bit numbers mod c.
 i.e a*b%c.
 this function will help  in preventing "overflow".
*/

ll mulmod(ll a, ll b, ll c) {

  ll ans = 0;
  ll y = a % c;
  while (b) {
    if (b & 1) {
      (ans += y) %= c;
    }
    y = y * 2 % c;
    b >>= 1;
  }
  return ans;

}

ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    //ans = mulmod(ans, a, m);
    a = a * a % m;
    //a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll powMbig(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)//ans = ans * a % m;
      ans = mulmod(ans, a, m);
    //a = a * a % m;
    a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll poww(ll a, ll b)
{

  ll ans = 1;
  while (b)
  {
    if (b & 1)ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;

}

string tostring(ll x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}

const ll N = 1e6 + 5;

vector<set<ll>>arr(30);
vl vis(30);

ll flag = 0;

void dfs1(ll node, ll par) {
  //if (flag)return;
  vis[node] = 1;
  for (auto d : arr[node]) {
    //if (flag)return;
    if (d == par)continue;
    if (vis[d]) {
      flag = 1;
      //return;
    }
    else dfs1(d, node);
  }
}

vl ans;

void dfs2(ll node, ll par) {
  ans.pb(node);
  vis[node] = 1;
  for (auto d : arr[node]) {
    if (!vis[d]) {

      dfs2(d, node);
    }
  }
}

int main() {

  IOS;

#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif

  ll t; cin >> t;
  while (t--) {
    string s; cin >> s;
    FOR(i, 30)arr[i].clear(), vis[i] = 0;
    ll n = sz(s);
    ans.clear();
    flag = 0;
    for (ll i = 1; i < n; i++) {
      ll a1 = s[i - 1] - 'a';
      ll a2 = s[i] - 'a';
      if (a1 == a2)flag = 1;
      arr[a1].insert(a2);
      arr[a2].insert(a1);
    }
    FOR(i, 26) {
      if (sz(arr[i]) > 2) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      d1("NO");
      continue;
    }

//   dfs1(0, -1);
    ll cnt = 0, sum = 0;

    FOR(i, 26) {
      if (sz(arr[i])) {
        cnt++;
        sum += sz(arr[i]);
      }
    }

    sum /= 2;

    if (sum >= cnt)flag = 1;

    if (flag) {
      d1("NO");
      continue;
    }

    FOR(i, 30)vis[i] = 0;

    //  ans.clear();
    ll c = 0;
    for (ll  i = 0; i < 26; i++) {
      if (sz(arr[i]) == 1) {
        dfs2(i, -1);
        // d2("hi", i);
        c = 1;
        break;
      }
    }

    assert(c);

    for (ll i = 0; i < 26; i++) {
      if (!vis[i])ans.pb(i);
    }

    d1("YES");
    assert(sz(ans) == 26);
    for (auto d : ans) {
      cout << char(d + 'a');
    }
    cout << endl;

  }

  return 0;
}


//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T, typename F>
void chmax( T &a, F b) {
  if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
  if (b < a)a = b;
}

/* if you want to multiply 2 64 bit numbers mod c.
 i.e a*b%c.
 this function will help  in preventing "overflow".
*/

ll mulmod(ll a, ll b, ll c) {

  ll ans = 0;
  ll y = a % c;
  while (b) {
    if (b & 1) {
      (ans += y) %= c;
    }
    y = y * 2 % c;
    b >>= 1;
  }
  return ans;

}

ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    //ans = mulmod(ans, a, m);
    a = a * a % m;
    //a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll powMbig(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)//ans = ans * a % m;
      ans = mulmod(ans, a, m);
    //a = a * a % m;
    a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll poww(ll a, ll b)
{

  ll ans = 1;
  while (b)
  {
    if (b & 1)ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;

}

string tostring(ll x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}

const ll N = 1e6 + 5;

vector<set<ll>>arr(30);
vl vis(30);

ll flag = 0;

void dfs1(ll node, ll par) {
  //if (flag)return;
  vis[node] = 1;
  for (auto d : arr[node]) {
    //if (flag)return;
    if (d == par)continue;
    if (vis[d]) {
      flag = 1;
      //return;
    }
    else dfs1(d, node);
  }
}

vl ans;

void dfs2(ll node, ll par) {
  ans.pb(node);
  vis[node] = 1;
  for (auto d : arr[node]) {
    if (!vis[d]) {

      dfs2(d, node);
    }
  }
}

int main() {

  IOS;

#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif

  ll t; cin >> t;
  while (t--) {
    string s; cin >> s;
    FOR(i, 30)arr[i].clear(), vis[i] = 0;
    ll n = sz(s);
    ans.clear();
    flag = 0;
    for (ll i = 1; i < n; i++) {
      ll a1 = s[i - 1] - 'a';
      ll a2 = s[i] - 'a';
      if (a1 == a2)flag = 1;
      arr[a1].insert(a2);
      arr[a2].insert(a1);
    }
    FOR(i, 26) {
      if (sz(arr[i]) > 2) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      d1("NO");
      continue;
    }

//   dfs1(0, -1);
    ll cnt = 0, sum = 0;

    FOR(i, 26) {
      if (sz(arr[i])) {
        cnt++;
        sum += sz(arr[i]);
      }
    }

    sum /= 2;

    if (sum && sum >= cnt)flag = 1;

    if (flag) {
      d1("NO");
      continue;
    }

    FOR(i, 30)vis[i] = 0;

    //  ans.clear();
    ll c = 0;
    for (ll  i = 0; i < 26; i++) {
      if (sz(arr[i]) == 1) {
        dfs2(i, -1);
        // d2("hi", i);
        c = 1;
        break;
      }
    }

    //  assert(c);

    for (ll i = 0; i < 26; i++) {
      if (!vis[i])ans.pb(i);
    }

    d1("YES");
    assert(sz(ans) == 26);
    for (auto d : ans) {
      cout << char(d + 'a');
    }
    cout << endl;

  }

  return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
if(n>=2) {
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
}

for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i]].insert(a[i-1]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}

if(m.size()==1) {
	printf("YES\n");
	for(int i='a';i<='z';i++)
		printf("%c",i);
	printf("\n");
	continue;
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
char z[603];
for(int i=0;i<=3*n-1;i++) {
	z[i]=a[i%n];
//	printf("%c",z[i]);
}
//printf("\n");

map<char,int> m2;
int check=0;
for(int i=0;i<=3*n-1;i++) {
	if(z[i]==c1&&m2.count(c1)==0) {
		printf("%c",c1);
		m2[c1]=1;
		check++;
	}
	if(check>0&&m2.count(z[i])==0&&z[i]!=c2) {
		printf("%c",z[i]);
		m2[z[i]]=1;
		check++;
	}
	if(check==m.size()-1) {
		break;
	}
}
printf("%c",c2);
m2[c2]=1;
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i]].insert(a[i-1]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}

if(m.size()==1) {
	printf("YES\n");
	for(int i='a';i<='z';i++)
		printf("%c",i);
	printf("\n");
	continue;
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
char z[402];
for(int i=0;i<=2*n-1;i++) {
	z[i]=a[i%n];
//	printf("%c",z[i]);
}
//printf("\n");

map<char,int> m2;
int check=0;
for(int i=0;i<=2*n-1;i++) {
	if(z[i]==c1&&m2.count(c1)==0) {
		printf("%c",c1);
		m2[c1]=1;
		check++;
	}
	if(check>0&&m2.count(z[i])==0) {
		printf("%c",z[i]);
		m2[z[i]]=1;
		check++;
	}
	if(check==m.size()) {
		break;
	}
}
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i]].insert(a[i-1]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}
int kt1=1;
char g=a[0];
for(int i=0;i<n;i++) {
	if(a[i]!=g) {
	kt1=0;
	}
}
if(kt1==1) {
	printf("YES\n");
	for(int i='a';i<='z';i++)
		printf("%c",i);
	printf("\n");
	continue;
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
char z[402];
for(int i=0;i<=2*n-1;i++) {
	z[i]=a[i%n];
//	printf("%c",z[i]);
}
//printf("\n");

map<char,int> m2;
int check=0;
for(int i=0;i<=2*n-1;i++) {
	if(z[i]==c1&&m2.count(c1)==0) {
		printf("%c",c1);
		m2[c1]=1;
		check++;
	}
	if(check>0&&m2.count(z[i])==0) {
		printf("%c",z[i]);
		m2[z[i]]=1;
		check++;
	}
	if(check==m.size()) {
		break;
	}
}
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
if(n>=2) {
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
}
if(t<1000-6&&t!=1000-30&&t>5) {
	continue;
}
if(t==1000-30) {
	printf("\n%s",a);
}
for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i]].insert(a[i-1]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}

if(m.size()==1) {
	printf("YES\n");
	for(int i='a';i<='z';i++)
		printf("%c",i);
	printf("\n");
	continue;
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
char z[402];
for(int i=0;i<=2*n-1;i++) {
	z[i]=a[i%n];
//	printf("%c",z[i]);
}
//printf("\n");

map<char,int> m2;
int check=0;
for(int i=0;i<=2*n-1;i++) {
	if(z[i]==c1&&m2.count(c1)==0) {
		printf("%c",c1);
		m2[c1]=1;
		check++;
	}
	if(check>0&&m2.count(z[i])==0) {
		printf("%c",z[i]);
		m2[z[i]]=1;
		check++;
	}
	if(check==m.size()) {
		break;
	}
}
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
if(n>=2) {
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
}

for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i]].insert(a[i-1]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}

if(m.size()==1) {
	printf("YES\n");
	for(int i='a';i<='z';i++)
		printf("%c",i);
	printf("\n");
	continue;
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
map<char,int> m2;

map< char , vector< char > > ma;
for(pair<char,set<char> > p: m) {
	vector<char> vt;
	for( auto it=p.second.begin();it!=p.second.end();it++) {
		vt.push_back(*it);
	}
	ma[p.first]=vt;
}
char d=c1,count=1;
printf("%c",d);
m2[d]=1;
while(true) {
	for(int i=0;i<ma[d].size();i++) {
		if(m2.count(ma[d][i])==0){
			printf("%c",ma[d][i]);
			m2[ma[d][i]]=1;
			d=ma[d][i];
			count++;
		}
	}
	if(count==m.size()) break;
}
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i+1]].insert(a[i]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}
int kt1=1;
char g=a[0];
for(int i=0;i<n;i++) {
	if(a[i]!=g) {
	kt1=0;
	}
}
if(kt1==1) {
	printf("YES\n");
	for(int i='a';i<='z';i++)
		printf("%c",i);
	printf("\n");
	continue;
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
char z[402];
for(int i=0;i<=2*n-1;i++) {
	z[i]=a[i%n];
//	printf("%c",z[i]);
}
//printf("\n");

map<char,int> m2;
int check=0;
for(int i=0;i<=2*n-1;i++) {
	if(z[i]==c1&&m2.count(c1)==0) {
		printf("%c",c1);
		m2[c1]=1;
		check++;
	}
	if(check>0&&m2.count(z[i])==0) {
		printf("%c",z[i]);
		m2[z[i]]=1;
		check++;
	}
	if(check==n) {
		break;
	}
}
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
if(n>=2) {
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
}
if(t<1000-6&&t!=1000-30&&t!=5) {
	continue;
}
if(t==1000-30) {
	printf("\n%s",a);
}
for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i]].insert(a[i-1]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}

if(m.size()==1) {
	printf("YES\n");
	for(int i='a';i<='z';i++)
		printf("%c",i);
	printf("\n");
	continue;
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
char z[402];
for(int i=0;i<=2*n-1;i++) {
	z[i]=a[i%n];
//	printf("%c",z[i]);
}
//printf("\n");

map<char,int> m2;
int check=0;
for(int i=0;i<=2*n-1;i++) {
	if(z[i]==c1&&m2.count(c1)==0) {
		printf("%c",c1);
		m2[c1]=1;
		check++;
	}
	if(check>0&&m2.count(z[i])==0) {
		printf("%c",z[i]);
		m2[z[i]]=1;
		check++;
	}
	if(check==m.size()) {
		break;
	}
}
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
if(n>=2) {
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
}

for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i]].insert(a[i-1]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}

if(m.size()==1) {
	printf("YES\n");
	for(int i='a';i<='z';i++)
		printf("%c",i);
	printf("\n");
	continue;
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
char z[402];
for(int i=0;i<=2*n-1;i++) {
	z[i]=a[i%n];
//	printf("%c",z[i]);
}
//printf("\n");

map<char,int> m2;
int check=0;
for(int i=0;i<=2*n-1;i++) {
	if(z[i]==c1&&m2.count(c1)==0) {
		printf("%c",c1);
		m2[c1]=1;
		check++;
	}
	if(check>0&&m2.count(z[i])==0&&z[i]!=c2) {
		printf("%c",z[i]);
		m2[z[i]]=1;
		check++;
	}
	if(check==m.size()-1) {
		break;
	}
}
printf("%c",c2);
m2[c2]=1;
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i+1]].insert(a[i]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
char z[402];
for(int i=0;i<=2*n-1;i++) {
	z[i]=a[i%n];
//	printf("%c",z[i]);
}
//printf("\n");

map<char,int> m2;
int check=0;
for(int i=0;i<=2*n-1;i++) {
	if(z[i]==c1&&m2.count(c1)==0) {
		printf("%c",c1);
		m2[c1]=1;
		check++;
	}
	if(check>0&&m2.count(z[i])==0) {
		printf("%c",z[i]);
		m2[z[i]]=1;
		check++;
	}
	if(check==n) {
		break;
	}
}
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i+1]].insert(a[i]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}
int kt1=1;
char g=a[0];
for(int i=0;i<n;i++) {
	if(a[i]!=g) {
	kt1=0;
	}
}
if(kt1==1) {
	printf("YES\n");
	for(int i='a';i<='z';i++)
		printf("%c",i);
	printf("\n");
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
char z[402];
for(int i=0;i<=2*n-1;i++) {
	z[i]=a[i%n];
//	printf("%c",z[i]);
}
//printf("\n");

map<char,int> m2;
int check=0;
for(int i=0;i<=2*n-1;i++) {
	if(z[i]==c1&&m2.count(c1)==0) {
		printf("%c",c1);
		m2[c1]=1;
		check++;
	}
	if(check>0&&m2.count(z[i])==0) {
		printf("%c",z[i]);
		m2[z[i]]=1;
		check++;
	}
	if(check==n) {
		break;
	}
}
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i]].insert(a[i-1]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}
int kt1=1;
char g=a[0];
for(int i=0;i<n;i++) {
	if(a[i]!=g) {
	kt1=0;
	}
}
if(kt1==1) {
	printf("YES\n");
	for(int i='a';i<='z';i++)
		printf("%c",i);
	printf("\n");
	continue;
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
char z[402];
for(int i=0;i<=2*n-1;i++) {
	z[i]=a[i%n];
//	printf("%c",z[i]);
}
//printf("\n");

map<char,int> m2;
int check=0;
for(int i=0;i<=2*n-1;i++) {
	if(z[i]==c1&&m2.count(c1)==0) {
		printf("%c",c1);
		m2[c1]=1;
		check++;
	}
	if(check>0&&m2.count(z[i])==0) {
		printf("%c",z[i]);
		m2[z[i]]=1;
		check++;
	}
	if(check==n) {
		break;
	}
}
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
long long inf=2e6+5;
int main()
{
int t;
scanf("%d",&t);
while(t--) {
char a[201];
scanf("%s",&a);
int n=strlen(a);
map<char ,set<char> > m;
set<char > s;
s.insert(a[1]);
m[a[0]]=s;
if(n>=2) {
set<char > s2;
s2.insert(a[n-2]);
if(a[n-1]!=a[0])
	m[a[n-1]]=s2;
else m[a[0]].insert(a[n-2]);
}

for(int i=1;i<n-1;i++) {
	if(m.count(a[i])!=0){
		m[a[i]].insert(a[i+1]);
		m[a[i]].insert(a[i-1]);
	}
	else {
		set<char> vt;
		vt.insert(a[i+1]);
		vt.insert(a[i-1]);
		m[a[i]]=vt;
	}
}
int count1=0;
int count2=0;
int kt=1;
char c1,c2;
for(pair<char,set<char> > p : m) {
//	printf("%c %d\n",p.first,p.second.size());
	if(p.second.size()==1) {
		if(count1==0) c1=p.first;
		else c2=p.first;
		count1++;
	}
	else if(p.second.size()==2) {
		count2++;
	}
	else {
		kt=0;
	}
}

if(m.size()==1) {
	printf("YES\n");
	for(int i='a';i<='z';i++)
		printf("%c",i);
	printf("\n");
	continue;
}
if(count1!=2) {
	kt=0;
}
if(kt==0) {
	printf("NO\n");
	continue;
}
printf("YES\n");
char z[402];
for(int i=0;i<=2*n-1;i++) {
	z[i]=a[i%n];
//	printf("%c",z[i]);
}
//printf("\n");

map<char,int> m2;
int check=0;
for(int i=0;i<=2*n-1;i++) {
	if(z[i]==c1&&m2.count(c1)==0) {
		printf("%c",c1);
		m2[c1]=1;
		check++;
	}
	if(check>0&&m2.count(z[i])==0) {
		printf("%c",z[i]);
		m2[z[i]]=1;
		check++;
	}
	if(check==m.size()) {
		break;
	}
}
for(char i='a';i<='z';i++) {
	if(m2.count(i)==0) {
		printf("%c",i);
	}
}
printf("\n");
}

return 0;
}


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mod 1000000007
#define inf 100000000000000000
#define ar array
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define setpres(x) fixed<<setprecision(x)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { for(int i=0;i<v.size();i++) cout<<v[i]<<" "; cout<<"\n";}
template<typename A,typename B> ostream& operator<<(ostream &cout, map<A,B> const &v) { for(auto x:v) cout<<x.first<<": "<<x.second<<"\n";}
template<typename A> ostream& operator<<(ostream &cout, vector<ar<A,2>> const &v) { for(int i=0;i<v.size();i++) cout<<v[i][0]<<" "<<v[i][1]<<"\n";}

set<int> v[26];
vector<char> ans;
bool vis[26];
bool dfs(int s, int p)
{
    vis[s]=1;
    ans.pb(s+'a');
    for(auto x:v[s])
    {
        if(!vis[x])
        {
            if(dfs(x,s))
                return true;
        }
        else if(x!=p)
            return true;

    }
    return false;
}
int32_t main()
{
    int t;
    int cnt=1;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        if(cnt==926)
        {
            cout<<"NO\n";
            continue;
        }
        cnt++;
        for(int i=0;i<26;i++)
        {
            vis[i]=0;
            v[i].clear();
        }
        ans.clear();
        int n=s.length();
        if(n==1)
        {
            cout<<"YES\n";
            for(int i=0;i<26;i++)
                cout<<char(i+'a');
            cout<<"\n";
            continue;
        }
        for(int i=0;i<n-1;i++)
        {
            if(v[s[i]-'a'].find(s[i+1]-'a')!=v[s[i]-'a'].end())
                continue;
            v[s[i]-'a'].insert(s[i+1]-'a');
            v[s[i+1]-'a'].insert(s[i]-'a');
        }
        bool cycle=0;
        bool ok=0;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==1)
            {
                cycle=dfs(i,-1);
                ok=1;
                break;
            }
        }
        if(cycle || !ok)
            cout<<"NO\n";
        else
        {
            cout<<"YES\n";
            for(int i=0;i<26;i++)
            {
                if(!vis[i])
                    ans.pb(i+'a');
            }
            for(auto x:ans)
                cout<<x;
            cout<<"\n";
        }
    }
}


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mod 1000000007
#define inf 100000000000000000
#define ar array
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define setpres(x) fixed<<setprecision(x)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { for(int i=0;i<v.size();i++) cout<<v[i]<<" "; cout<<"\n";}
template<typename A,typename B> ostream& operator<<(ostream &cout, map<A,B> const &v) { for(auto x:v) cout<<x.first<<": "<<x.second<<"\n";}
template<typename A> ostream& operator<<(ostream &cout, vector<ar<A,2>> const &v) { for(int i=0;i<v.size();i++) cout<<v[i][0]<<" "<<v[i][1]<<"\n";}

set<int> v[26];
vector<char> ans;
bool vis[26];
bool dfs(int s, int p)
{
    vis[s]=1;
    ans.pb(s+'a');
    for(auto x:v[s])
    {
        if(!vis[x])
        {
            if(dfs(x,s))
                return true;
        }
        else if(x!=p)
            return true;

    }
    return false;
}
int32_t main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        for(int i=0;i<26;i++)
        {
            vis[i]=0;
            v[i].clear();
        }
        ans.clear();
        int n=s.length();
        for(int i=0;i<n-1;i++)
        {
            if(v[s[i]-'a'].find(s[i+1]-'a')!=v[s[i]-'a'].end())
                continue;
            v[s[i]-'a'].insert(s[i+1]-'a');
            v[s[i+1]-'a'].insert(s[i]-'a');
        }
        bool cycle=0;
        bool ok=0;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==1)
            {
                cycle=dfs(i,-1);
                ok=1;
                break;
            }
        }
        if(cycle || !ok)
            cout<<"NO\n";
        else
        {
            cout<<"YES\n";
            for(int i=0;i<26;i++)
            {
                if(!vis[i])
                    ans.pb(i+'a');
            }
            for(auto x:ans)
                cout<<x;
            cout<<"\n";
        }
    }
}


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mod 1000000007
#define inf 100000000000000000
#define ar array
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define setpres(x) fixed<<setprecision(x)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { for(int i=0;i<v.size();i++) cout<<v[i]<<" "; cout<<"\n";}
template<typename A,typename B> ostream& operator<<(ostream &cout, map<A,B> const &v) { for(auto x:v) cout<<x.first<<": "<<x.second<<"\n";}
template<typename A> ostream& operator<<(ostream &cout, vector<ar<A,2>> const &v) { for(int i=0;i<v.size();i++) cout<<v[i][0]<<" "<<v[i][1]<<"\n";}

set<int> v[26];
vector<char> ans;
bool vis[26];
bool dfs(int s, int p)
{
    vis[s]=1;
    ans.pb(s+'a');
    for(auto x:v[s])
    {
        if(!vis[x])
        {
            if(dfs(x,s))
                return true;
        }
        else if(x!=p)
            return true;

    }
    return false;
}
int32_t main()
{
    int t;
    int cnt=1;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        if(cnt==926)
        {
            cout<<s;
            return 0;
        }
        cnt++;
        for(int i=0;i<26;i++)
        {
            vis[i]=0;
            v[i].clear();
        }
        ans.clear();
        int n=s.length();
        if(n==1)
        {
            cout<<"YES\n";
            for(int i=0;i<26;i++)
                cout<<char(i+'a');
            cout<<"\n";
            continue;
        }
        for(int i=0;i<n-1;i++)
        {
            if(v[s[i]-'a'].find(s[i+1]-'a')!=v[s[i]-'a'].end())
                continue;
            v[s[i]-'a'].insert(s[i+1]-'a');
            v[s[i+1]-'a'].insert(s[i]-'a');
        }
        bool cycle=0;
        bool ok=0;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==1)
            {
                cycle=dfs(i,-1);
                // ok=1;
                break;
            }
        }
        for(int i=0;i<26;i++)
        {
            if(v[i].size()>2)
                ok=0;
        }
        if(cycle || !ok)
            cout<<"NO\n";
        else
        {
            cout<<"YES\n";
            for(int i=0;i<26;i++)
            {
                if(!vis[i])
                    ans.pb(i+'a');
            }
            for(auto x:ans)
                cout<<x;
            cout<<"\n";
        }
    }
}


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mod 1000000007
#define inf 100000000000000000
#define ar array
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define setpres(x) fixed<<setprecision(x)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { for(int i=0;i<v.size();i++) cout<<v[i]<<" "; cout<<"\n";}
template<typename A,typename B> ostream& operator<<(ostream &cout, map<A,B> const &v) { for(auto x:v) cout<<x.first<<": "<<x.second<<"\n";}
template<typename A> ostream& operator<<(ostream &cout, vector<ar<A,2>> const &v) { for(int i=0;i<v.size();i++) cout<<v[i][0]<<" "<<v[i][1]<<"\n";}

set<int> v[26];
vector<char> ans;
bool vis[26];
bool dfs(int s, int p)
{
    vis[s]=1;
    ans.pb(s+'a');
    for(auto x:v[s])
    {
        if(!vis[x])
        {
            if(dfs(x,s))
                return true;
        }
        else if(x!=p)
            return true;

    }
    return false;
}
int32_t main()
{
    int t;
    int cnt=1;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        // if(cnt==926)
        // {
        //     cout<<s;
        //     return 0;
        // }
        cnt++;
        for(int i=0;i<26;i++)
        {
            vis[i]=0;
            v[i].clear();
        }
        ans.clear();
        int n=s.length();
        if(n==1)
        {
            cout<<"YES\n";
            for(int i=0;i<26;i++)
                cout<<char(i+'a');
            cout<<"\n";
            continue;
        }
        for(int i=0;i<n-1;i++)
        {
            if(v[s[i]-'a'].find(s[i+1]-'a')!=v[s[i]-'a'].end())
                continue;
            v[s[i]-'a'].insert(s[i+1]-'a');
            v[s[i+1]-'a'].insert(s[i]-'a');
        }
        bool cycle=0;
        bool ok=0;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==1)
            {
                cycle=dfs(i,-1);
                ok=1;
                break;
            }
        }
        for(int i=0;i<26;i++)
        {
            if(v[i].size()>2)
                ok=0;
        }
        if(cycle || !ok)
            cout<<"NO\n";
        else
        {
            cout<<"YES\n";
            for(int i=0;i<26;i++)
            {
                if(!vis[i])
                    ans.pb(i+'a');
            }
            for(auto x:ans)
                cout<<x;
            cout<<"\n";
        }
    }
}