Problem: A robot in a two-dimensional maze again. The maze has an entrance and an exit this time, though.

Just as in the previous problem, the maze is made up of H × W grid cells, its upper side faces north, and each cell is either empty or wall. Unlike the previous, on the other hand, one of the empty cells is connected to the entrance and another to the exit.

The robot is rather complex - there is some control, but not full. It is associated with a controller that has two buttons, namely forward and turn. The forward button moves the robot forward to the next cell, if possible. The robot can not move into a wall nor outside the maze. The turn button turns the robot as programmed. Here the program is a finite sequence of N commands, each of which is either 'L' (indicating a left turn) or 'R' (a right turn). The first turn follows the first command; the second turn follows the second command; similar for the following turns. The turn button stops working once the commands are exhausted; the forward button still works in such a case though. The robot always turns by 90 degrees at once.

The robot is initially put on the entrance cell, directed to the north. Your mission is to determine whether it can reach the exit cell if controlled properly.



Input

The input is a sequence of datasets. Each dataset is formatted as follows.

H W N
s1 ... sN
c1,1c1,2...c1,W
...
cH,1cH,2...cH,W


The first line of a dataset contains three integers H, W and N (1 ≤ H, W ≤ 1,000, 1 ≤ N ≤ 1,000,000).

The second line contains a program of N commands.

Each of the following H lines contains exactly W characters. Each of these characters represents a cell of the maze. "." indicates empty, "#" indicates a wall, "S" indicates an entrance, and "G" indicates an exit. There is exactly one entrance cell and one exit cell.

The end of input is indicated by a line with three zeros.

Output

For each dataset, output whether the robot can reach the exit in a line: "Yes" if it can or "No" otherwise (without quotes).

Examples

Input

2 2 1
L
G.
#S
2 2 2
RR
G.
.S
3 3 6
LLLLLL
G#.
...
.#S
0 0 0


Output

Yes
No
Yes


Input

2 2 1
L
G.
S
2 2 2
RR
G.
.S
3 3 6
LLLLLL
G#.
...
.#S
0 0 0


Output

Yes
No
Yes

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
enum class Direction {
	North, East, South, West
};
Direction from_int(const int n) {
	switch (n % 4) {
	case 0: return Direction::North;
	case 1: return Direction::East;
	case 2: return Direction::South;
	case 3: return Direction::West;
	default: throw 0;
	}
}
int to_int(const Direction dir) {
	switch (dir) {
	case Direction::North: return 0;
	case Direction::East: return 1;
	case Direction::South: return 2;
	case Direction::West: return 3;
	default: throw 0;
	}
}
Direction turn(const Direction current, const char order) {
	switch (order) {
	case 'L': return from_int(to_int(current) + 3);
	case 'R': return from_int(to_int(current) + 1);
	default: throw 0;
	}
}
struct Coordinate {
	int x, y;
	Coordinate move(const Direction dir) const {
		switch (dir) {
		case Direction::North: return Coordinate{ x, y - 1 };
		case Direction::East: return Coordinate{ x + 1, y };
		case Direction::South: return Coordinate{ x, y + 1 };
		case Direction::West: return Coordinate{ x - 1, y };
		default: throw 0;
		}
	}
};
int main() {
	while (true) {
		int h, w, n; std::cin >> h >> w >> n; if (h == 0 && w == 0 && n == 0) break;
		std::string order; std::cin >> order;
		std::vector<Direction> directions{ Direction::North };
		for (const char c : order) {
			directions.push_back(turn(directions.back(), c));
		}
		std::vector<std::vector<int>> next_direction(n + 1);
		{
			std::vector<int> prev{ n + 1, n + 1, n + 1, n + 1};
			for (int i = n; i >= 0; --i) {
				prev[to_int(directions[i])] = i;
				next_direction[i] = prev;
			}
		}
		std::vector<std::string> state(h); for (auto& line : state) std::cin >> line;
		Coordinate start{ -1, -1 }, goal{ -1, -1 };
		for (auto y = 0; y < h; ++y) for (auto x = 0; x < w; ++x) {
			if (state[y][x] == 'S') start = Coordinate{ x, y };
			if (state[y][x] == 'G') goal = Coordinate{ x, y };
		}
		std::vector<std::vector<std::vector<int>>> min_step(h, std::vector<std::vector<int>>(w, std::vector<int>(4, INT_MAX))); min_step[start.y][start.x][to_int(Direction::North)] = 0;
		std::vector<std::queue<Coordinate>> history(n + 1); history[0].push(start);
		bool can_reach = false;
		for (auto i = 0; i <= n && !can_reach; ++i) {
			while (!history[i].empty()) {
				const auto top = history[i].front(); history[i].pop();
				if (min_step[top.y][top.x][to_int(directions[i])] != i) continue;
				const auto next_pos = top.move(directions[i]);
				if (0 <= next_pos.y && next_pos.y < h && 0 <= next_pos.x && next_pos.x < w && state[next_pos.y][next_pos.x] != '#') {
					if (min_step[next_pos.y][next_pos.x][to_int(directions[i])] > i) {
						min_step[next_pos.y][next_pos.x][to_int(directions[i])] = i;
						if (next_pos.x == goal.x && next_pos.y == goal.y) {
							can_reach = true;
							break;
						}
						history[i].emplace(next_pos);
					}
				}
				for (const auto next_dir : next_direction[i]) if (next_dir <= n) {
					if (min_step[top.y][top.x][to_int(directions[next_dir])] > next_dir) {
						min_step[top.y][top.x][to_int(directions[next_dir])] = next_dir;
						history[next_dir].emplace(top);
					}
				}
			}
		}
		if (can_reach || std::any_of(min_step[goal.y][goal.x].begin(), min_step[goal.y][goal.x].end(), [](const int step) {return step != INT_MAX; })) {
			std::cout << "Yes\n";
		}
		else {
			std::cout << "No\n";
		}
	}
}