T = int(input())

for t in range(1, T+1):
    p = input()
    n = int(input())
    x = input()[1:-1]
    if len(x) > 0:
        x = list(map(int, x.split(',')))
    cnt = 0
    ans = True
    r_cut, l_cut = 0, 0

    for i in p:
        if i == 'R' and len(x) > 0:
            cnt += 1
            r_cut, l_cut = l_cut, r_cut
        elif i == 'D':
            if r_cut + l_cut == len(x):
                ans = False
                break
            else:
                l_cut += 1

    if ans:
        if cnt % 2 == 1:
            x.reverse()

        x = x[l_cut:len(x)-r_cut]

        x = str(x)[1:-1]
        x = x.replace(', ', '')
        print("[" + ",".join(x) + "]")
    else:
        print('error')