#include <bits/stdc++.h>   struct node {     char a;     struct node *left;     struct node *right;   };   int main() {     int t, len;     char ch[205];     struct node *p, *q, *r[26];     scanf( %d , &t);     getchar();     while (t--) {       int flag = 0;       scanf( %s , ch);       len = strlen(ch);       for (int i = 0; i < 26; i++) r[i] = NULL;       for (int i = 0; i < len; i++) {         if (r[ch[i] -  a ] == NULL) {           p = (struct node *)malloc(sizeof(struct node));           p->a = ch[i];           p->left = NULL;           p->right = NULL;           r[ch[i] -  a ] = p;           if (i > 0) {             if (r[ch[i - 1] -  a ]->left == NULL) {               r[ch[i - 1] -  a ]->left = p;               p->right = r[ch[i - 1] -  a ];             } else if (r[ch[i - 1] -  a ]->right == NULL) {               r[ch[i - 1] -  a ]->right = p;               p->left = r[ch[i - 1] -  a ];             } else {               printf( NO n );               flag = 1;               break;             }           }         } else {           if (r[ch[i] -  a ]->left != r[ch[i - 1] -  a ] &&               r[ch[i] -  a ]->right != r[ch[i - 1] -  a ]) {             printf( NO n );             flag = 1;             break;           }         }       }       if (flag == 1) continue;       printf( YES n );       for (int i = 0; i < 26; i++) {         if (r[i] != NULL) {           q = r[i];           while (q->left != NULL) q = q->left;           while (q != NULL) {             printf( %c , q->a);             q = q->right;           }           break;         }       }       for (int i = 0; i < 26; i++)         if (r[i] == NULL) printf( %c , i +  a );       printf(  n );     }   }   