def moving(row, col, direction):
if direction == "up":
return row - 1, col
if direction == "down":
return row + 1, col
if direction == "left":
return row, col - 1
if direction == "right":
return row, col + 1
size = int(input())
directions = input().split(', ')
matrix = []
s_row = 0
s_col = 0
for row in range(size):
row_elements = list(input())
for col in range(size):
if row_elements[col] == "s":
s_row = row
s_col = col
matrix.append(row_elements)
hazelnuts = 0
while True:
matrix[s_row][s_col] = "*"
for direction in directions:
next_row, next_col = moving(s_row, s_col, direction)
if next_row < 0 or next_col < 0 or next_row >= size or next_col >= size:
print(f'The squirrel is out of the field.')
break
s_row, s_col = next_row, next_col
if matrix[s_row][s_col] == "t":
print(f'Unfortunately, the squirrel stepped on a trap...')
break
if matrix[s_row][s_col] == "h":
hazelnuts += 1
if hazelnuts == 3:
print(f'Good job! You have collected all hazelnuts!')
break
print(f'Hazelnuts collected: {hazelnuts}')