------
## 最终结论
To solve the problem of assembling a perfect keyboard layout for Polycarp, we need to ensure that for each password string, adjacent characters are also adjacent on the keyboard. Here's a step-by-step breakdown of how we can achieve this:

1. **Input Parsing**: First, we'll read the number of test cases and each password string.

2. **Graph Construction**: For each password string, construct a graph where each character is a node and edges exist between nodes if they are adjacent in the password.

3. **Check Adjacency Constraints**: Ensure that no character has more than two neighbors in the graph because otherwise, it would be impossible to lay them out in a single row without breaking adjacency.

4. **Identify Starting Point**: Find a character with exactly one neighbor to start laying out the keyboard (if possible). This will act as one end of our row.

5. **Depth-First Search (DFS) for Layout**: Use DFS from the starting character to visit all connected characters and form the initial part of the layout.

6. **Complete Layout**: Append any remaining characters that were not part of the password to complete the full 26-character keyboard layout.

7. **Output Results**: For each test case, output "YES" followed by a valid layout or "NO" if it's impossible.

Here's the Python code implementing this approach:

```python
def read_input():
    import sys
    input = sys.stdin.read
    data = input().strip().split()
    return data

data = read_input()

T = int(data[0])
results = []

for i in range(1, T + 1):
    s = data[i]
    
    # Create adjacency list
    adj = {ch: set() for ch in 'abcdefghijklmnopqrstuvwxyz'}
    
    for j in range(len(s) - 1):
        a, b = s[j], s[j + 1]
        adj[a].add(b)
        adj[b].add(a)
    
    # Check if possible to create such a layout
    possible = True
    start_char = None
    
    # Find starting point and check adjacency constraints
    for ch in adj:
        if len(adj[ch]) > 2:
            possible = False
            break
        if len(adj[ch]) == 1:
            start_char = ch
    
    if not possible or start_char is None:
        results.append("NO")
        continue
    
    # Perform DFS to build layout
    visited = set()
    layout = []
    
    def dfs(ch):
        visited.add(ch)
        layout.append(ch)
        for neighbor in adj[ch]:
            if neighbor not in visited:
                dfs(neighbor)
    
    dfs(start_char)
    
    # Check if all characters from `s` are visited
    unique_chars_in_s = set(s)
    
    if len(layout) != len(unique_chars_in_s):
        results.append("NO")
        continue
    
    # Add remaining characters to complete the keyboard layout
    remaining_chars = [ch for ch in 'abcdefghijklmnopqrstuvwxyz' if ch not in layout]
    layout.extend(remaining_chars)
    
    results.append("YES\n" + "".join(layout))

# Print results
print("\n".join(results))
```

This solution efficiently handles up to 1000 test cases with strings of length up to 200, ensuring that we find a valid single-row keyboard layout or determine it's impossible given the constraints.