'''
Validator for PPCG challenge.

Provide input and output filenames as arguments or input and output as stdin (2 lines input and then 1line output).
'''
import sys

if len(sys.argv)==3:
    with open(sys.argv[1]) as f:
        si=f.readline().rstrip()
        so=f.readline().rstrip()
    with open(sys.argv[2]) as f:
        moves=f.readline().rstrip()
else:
    si=input()
    so=input()
    moves=input()    
if sorted(si)!=sorted(so):
    print('incompatible start and goal strings')
    exit()
d={'u':(0,-1),'d':(0,1),'l':(-1,0),'r':(1,0)}
p=[]
for i in range(len(si)):
    p+=[(i,0)]
for i,move in enumerate(moves.split()):
    try:
        poss,dir=move.split(':')
        pos=int(poss)
        p[pos]=tuple(a+b for a,b in zip(p[pos],d[dir]))
        if len(set(p))<len(si):
            print('letters at the same position at move',i+1)
            exit()
    except:
        print('format error at move',i+1)
        exit()
step_count=i+1
r=set()
for i,pe in enumerate(p):
    if pe[1]==0 and 0<=pe[0]<len(so) and si[i]==so[pe[0]]:
        r.add(pe[0])
    else:
        print('goal string not reached')
        exit()
if len(r)!=len(so):
    print('goal string not reached')
else:
    print('move sequence verified with step count',step_count)
    