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 <algorithm>
#include <cstring>
#include <queue>

using namespace std;

int h,w,n;
char ss[1000001];
char field[1001][1001];
int sx,sy;
int gx,gy;

const int dy[]={-1,0,1,0};
const int dx[]={0,1,0,-1};

int d[4][1001][1001];
int toAng[4][4][1000001];
const int INF=1000000000;

typedef pair<int,int> pii;

int dfs(int cang,int oang,int pos){
	if(cang==oang)return pos;
	else if(pos==n)return INF;
	else if(toAng[cang][oang][pos]!=-1)return toAng[cang][oang][pos];
	int nang;
	if(ss[pos]=='L')nang=(cang-1+4)%4;
	else nang=(cang+1)%4;
	return toAng[cang][oang][pos]=dfs(nang,oang,pos+1);
}

bool bfs(){
	memset(toAng,-1,sizeof(toAng));

	// »ÝÌü«©çÚIÌü«ÖÚ®·éÌÉÇ±ÜÅ^[ðg¤Kvª é©vZ
	// ìêÈ¢ÈçÎINF
	// cang==oagn
//	for(int i=0;i<4;i++)for(int j=0;j<n;j++)toAng[i][i][j]=i;
//	// cang!=oang&&pos==n
//	for(int i=0;i<4;i++)for(int j=0;j<4;j++)if(i!=j)toAng[i][j][n]=INF;
//	for(int k=n-1;k>=0;k--){
//		for(int i=0;i<4;i++){
//			for(int j=0;j<4;j++){
//				if(j==i)continue;
//				int nang;
//				int cang=i;
//				int oang=j;
//				int pos=k;
//				if(ss[pos]=='L')nang=(cang-1+4)%4;
//				else nang=(cang+1)%4;
//				toAng[cang][oang][pos]=toAng[nang][oang][pos+1];
//			}
//		}
//	}
	//  éêÖB·éÌÉKvÈÅ¬^[
	priority_queue<pair<pii,pii>,vector<pair<pii,pii> >,greater<pair<pii,pii> > > pq;
	for(int i=0;i<4;i++)for(int j=0;j<1001;j++)for(int k=0;k<1001;k++)d[i][j][k]=INF;
	pq.push(make_pair(pii(0,0),pii(sy,sx)));
	d[0][sy][sx]=0;
	while(pq.size()){
		pair<pii,pii> p=pq.top();
		pq.pop();
		int cx=p.second.second;
		int cy=p.second.first;
		int cang=p.first.second;
		int cpos=p.first.first;
		// àµ»ÝÌRXgæè¬³¢àÌª·ÅÉ¶ÝµÄ¢½ÌÈçÎ
		if(d[cang][cy][cx]<cpos)continue;
		// 4ûüÖÚ®
		for(int i=0;i<4;i++){
			int ny=cy+dy[i];
			int nx=cx+dx[i];
			int nang=i;
			// ÌûüðìêéÜÅposðißé
			//int npos=toAng[cang][nang][cpos];
			int npos=dfs(cang,nang,cpos);
			if(npos!=INF&&ny>=0&&nx>=0&&ny<h&&nx<w&&field[ny][nx]=='.'&&d[nang][ny][nx]>npos){
				d[nang][ny][nx]=npos;
				pq.push(make_pair(pii(npos,nang),pii(ny,nx)));
			}
		}
	}
	for(int i=0;i<4;i++)if(d[i][gy][gx]!=INF)return true;
	return false;
}

int main(){
	while(cin>>h>>w>>n&&(h|w|n)){
		for(int i=0;i<n;i++)cin>>ss[i];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			cin>>field[i][j];
			if(field[i][j]=='S'){
				sx=j;
				sy=i;
				field[i][j]='.';
			}
			else if(field[i][j]=='G'){
				gx=j;
				gy=i;
				field[i][j]='.';
			}
		}
		if(bfs())cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}