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

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

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

Input

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

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

Output

For each test case, do the following:

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

Example

Input


5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza


Output


YES
bacdefghijklmnopqrstuvwxyz
YES
edocabfghijklmnpqrstuvwxyz
NO
YES
xzytabcdefghijklmnopqrsuvw
NO

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.StringTokenizer;

public class keyboard {
    public static void main(String[] args) throws IOException {
        FastScanner fs = new FastScanner();
        int t = fs.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < t; i++) {
            String s = fs.next();
            char[][] map = new char[26][2];
            for (int j = 0; j < 26; j++) {
                Arrays.fill(map[j], '$');
            }

            boolean possible = true;
            for (int j = 0; j < s.length(); j++) {
                int charNum = s.codePointAt(j) - (int)'a';
                if(j != 0){
                    int prev = s.codePointAt(j - 1) - (int) 'a';
                    if(map[prev][0] != (char) (charNum + (int) 'a')
                    && map[prev][1] != (char) (charNum + (int) 'a')){
                        if(map[prev][0] == '$'){
                            map[prev][0] = (char) (charNum + (int) 'a');
                        } else if(map[prev][1] == '$'){
                            map[prev][1] = (char) (charNum + (int) 'a');
                        } else {
                            possible = false;
                            break;
                        }
                    }
                    if(map[charNum][0] != (char) (prev + (int) 'a')
                            && map[charNum][1] != (char) (prev + (int) 'a')){
                        if(map[charNum][0] == '$'){
                            map[charNum][0] = (char) (prev + (int) 'a');
                        } else if(map[charNum][1] == '$'){
                            map[charNum][1] = (char) (prev + (int) 'a');
                        } else {
                            possible = false;
                            break;
                        }
                    }
                }
                if(j != s.toCharArray().length-1){
                    int next = s.codePointAt(j + 1) - (int) 'a';
                    if(map[next][0] != (char) (charNum + (int) 'a')
                            && map[next][1] != (char) (charNum + (int) 'a')){
                        if(map[next][0] == '$'){
                            map[next][0] = (char) (charNum + (int) 'a');
                        } else if(map[next][1] == '$'){
                            map[next][1] = (char) (charNum + (int) 'a');
                        } else {
                            possible = false;
                            break;
                        }
                    }
                    if(map[charNum][0] != (char) (next + (int) 'a')
                            && map[charNum][1] != (char) (next + (int) 'a')){
                        if(map[charNum][0] == '$'){
                            map[charNum][0] = (char) (next + (int) 'a');
                        } else if(map[charNum][1] == '$'){
                            map[charNum][1] = (char) (next + (int) 'a');
                        } else {
                            possible = false;
                            break;
                        }
                    }
                }
            }
            Deque<Character> layout = new ArrayDeque<>();
            if(possible){
                // build keyboard layout
                boolean[] used = new boolean[26];
                char currLetter = s.charAt(0);
                int currLetterNum = (int) currLetter - (int) 'a';
                char nextLetter;
                int nextLetterNum;
                layout.addLast(currLetter);
                used[currLetterNum] = true;
                //dfs
                while(true){
                    if ((map[currLetterNum][0] == '$' || map[currLetterNum][0] == '.')
                            && (map[currLetterNum][1] == '$' || map[currLetterNum][1] == '.')) {
                        break;
                    }
                    if(map[currLetterNum][0] != '.'
                    && map[currLetterNum][0] != '$'){
                        nextLetter = map[currLetterNum][0];
                        map[currLetterNum][0] = '.';
                    } else {
                        nextLetter = map[currLetterNum][1];
                        map[currLetterNum][1] = '.';
                    }
                    nextLetterNum = (int) nextLetter - (int) 'a';
                    if(used[nextLetterNum]){
                        possible = false;
                        break;
                    } else {
                        layout.addLast(nextLetter);
                        used[nextLetterNum] = true;
                        if(map[nextLetterNum][0] == currLetter){
                            map[nextLetterNum][0] = '.';
                        } else {
                            map[nextLetterNum][1] = '.';
                        }
                    }
                    currLetter = nextLetter;
                    currLetterNum = (int) currLetter - (int) 'a';
                }
                if(map[s.codePointAt(0) - (int)'a'][1] != '$'){
                    currLetter = s.charAt(0);
                    currLetterNum = (int) currLetter - (int) 'a';
                    while(true){
                        if ((map[currLetterNum][0] == '$' || map[currLetterNum][0] == '.')
                                && (map[currLetterNum][1] == '$' || map[currLetterNum][1] == '.')) {
                            break;
                        }
                        if(map[currLetterNum][0] != '.'
                                && map[currLetterNum][0] != '$'){
                            nextLetter = map[currLetterNum][0];
                            map[currLetterNum][0] = '.';
                        } else {
                            nextLetter = map[currLetterNum][1];
                            map[currLetterNum][1] = '.';
                        }
                        nextLetterNum = (int) nextLetter - (int) 'a';
                        if(used[nextLetterNum]){
                            possible = false;
                            break;
                        } else {
                            layout.addFirst(nextLetter);
                            used[nextLetterNum] = true;
                            if(map[nextLetterNum][0] == currLetter){
                                map[nextLetterNum][0] = '.';
                            } else {
                                map[nextLetterNum][1] = '.';
                            }
                        }
                        currLetter = nextLetter;
                        currLetterNum = (int) currLetter - (int) 'a';
                    }
                }
                //add remaining letters to the end
                for(int j = 0; j < 26; ++j){
                    currLetter = (char) ( (int)'a' + j );
                    currLetterNum = (int) currLetter - (int) 'a';
                    if(!used[currLetterNum]){
                        layout.addLast(currLetter);
                    }
                }
            }
            if(!possible){
                sb.append("NO\n");
            } else {
                sb.append("YES\n");
                for (int j = 0; j < 26; j++) {
                    sb.append(layout.pop());
                }
                sb.append('\n');
            }
        }
        System.out.println(sb);
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}