#!/usr/bin/python3 size = input().split(" ") assert len(size) == 2 size_y = int(size[0]) size_x = int(size[1]) pos = input().split(" ") assert len(pos) == 2 pos_y = int(pos[0]) pos_x = int(pos[1]) assert 0 < pos_y <= size_y assert 0 < pos_x <= size_x num_moves = int(input()) moves = input() assert len(moves) == num_moves for move in moves: diff_y = 0 diff_x = 0 if move == "^": diff_y = -1 elif move == "v": diff_y = 1 elif move == "<": diff_x = -1 elif move == ">": diff_x = 1 else: assert False if (0 < pos_y + diff_y <= size_y) and (0 < pos_x + diff_x <= size_x): pos_y += diff_y pos_x += diff_x print(pos_y, pos_x)