from itertools import permutations
import string

def next_permutation(arr):
    # Find non-increasing suffix
    i = len(arr) - 1
    while i > 0 and arr[i - 1] >= arr[i]:
        i -= 1
    if i <= 0:
        return 0
    # Find successor to pivot
    j = len(arr) - 1
    while arr[j] <= arr[i - 1]:
        j -= 1
    arr[i - 1], arr[j] = arr[j], arr[i - 1]
    
    # Reverse suffix
    arr[i : ] = arr[len(arr) - 1 : i - 1 : -1]
    return arr
n = int(input())
for _ in range(n):
    w = input()
    w = [ord(x) for x in w]
    res = next_permutation(w)
    if res == 0:
        print("no answer")
    else:
        w = [chr(x) for x in res ]
        print(''.join([str(x) for x in w]))
        

caf48d0fdbe4dc13291d6a6562d00969e3ca2df1
<mask token>


def next_permutation(arr):
    i = len(arr) - 1
    while i > 0 and arr[i - 1] >= arr[i]:
        i -= 1
    if i <= 0:
        return 0
    j = len(arr) - 1
    while arr[j] <= arr[i - 1]:
        j -= 1
    arr[i - 1], arr[j] = arr[j], arr[i - 1]
    arr[i:] = arr[len(arr) - 1:i - 1:-1]
    return arr


<mask token>

<mask token>


def next_permutation(arr):
    i = len(arr) - 1
    while i > 0 and arr[i - 1] >= arr[i]:
        i -= 1
    if i <= 0:
        return 0
    j = len(arr) - 1
    while arr[j] <= arr[i - 1]:
        j -= 1
    arr[i - 1], arr[j] = arr[j], arr[i - 1]
    arr[i:] = arr[len(arr) - 1:i - 1:-1]
    return arr


<mask token>
for _ in range(n):
    w = input()
    w = [ord(x) for x in w]
    res = next_permutation(w)
    if res == 0:
        print('no answer')
    else:
        w = [chr(x) for x in res]
        print(''.join([str(x) for x in w]))

<mask token>


def next_permutation(arr):
    i = len(arr) - 1
    while i > 0 and arr[i - 1] >= arr[i]:
        i -= 1
    if i <= 0:
        return 0
    j = len(arr) - 1
    while arr[j] <= arr[i - 1]:
        j -= 1
    arr[i - 1], arr[j] = arr[j], arr[i - 1]
    arr[i:] = arr[len(arr) - 1:i - 1:-1]
    return arr


n = int(input())
for _ in range(n):
    w = input()
    w = [ord(x) for x in w]
    res = next_permutation(w)
    if res == 0:
        print('no answer')
    else:
        w = [chr(x) for x in res]
        print(''.join([str(x) for x in w]))

from itertools import permutations
import string


def next_permutation(arr):
    i = len(arr) - 1
    while i > 0 and arr[i - 1] >= arr[i]:
        i -= 1
    if i <= 0:
        return 0
    j = len(arr) - 1
    while arr[j] <= arr[i - 1]:
        j -= 1
    arr[i - 1], arr[j] = arr[j], arr[i - 1]
    arr[i:] = arr[len(arr) - 1:i - 1:-1]
    return arr


n = int(input())
for _ in range(n):
    w = input()
    w = [ord(x) for x in w]
    res = next_permutation(w)
    if res == 0:
        print('no answer')
    else:
        w = [chr(x) for x in res]
        print(''.join([str(x) for x in w]))

from itertools import permutations
import string

def next_permutation(arr):
    # Find non-increasing suffix
    i = len(arr) - 1
    while i > 0 and arr[i - 1] >= arr[i]:
        i -= 1
    if i <= 0:
        return 0
    # Find successor to pivot
    j = len(arr) - 1
    while arr[j] <= arr[i - 1]:
        j -= 1
    arr[i - 1], arr[j] = arr[j], arr[i - 1]
    
    # Reverse suffix
    arr[i : ] = arr[len(arr) - 1 : i - 1 : -1]
    return arr
n = int(input())
for _ in range(n):
    w = input()
    w = [ord(x) for x in w]
    res = next_permutation(w)
    if res == 0:
        print("no answer")
    else:
        w = [chr(x) for x in res ]
        print(''.join([str(x) for x in w]))
        
