#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

int Psz;
struct PMA{
	int n;
	PMA *next[0x200];
	vector<int> accept;
	PMA() { fill(next, next+0x200, (PMA*)0); }
	PMA(int a)
	{
		n=a;
		fill(next, next+0x200, (PMA*)0);
	}
};

PMA *buildPMA(vector<string>& p, vector<PMA*>& vpma, int size)
{
	Psz=0;
	PMA *root = new PMA(Psz++);
	vpma.push_back(root);
	for(int i=0; i<size; i++)
	{
		PMA* t=root;
		for(int j=0; j<p[i].size(); j++)
		{
			char c=p[i][j];
			if(t->next[c] == NULL)
			{
				t->next[c] = new PMA(Psz++);
				vpma.push_back(t->next[c]);
			}
			t = t->next[c];
		}
	}

	queue<PMA*> Q;
	for(int c = 'A'; c<='Z'; c++)
	{
		if(root->next[c])
		{
			root->next[c]->next[0]=root;
			Q.push(root->next[c]);
		}
		else
		{
			root->next[c] = root;
		}
	}

	while(!Q.empty())
	{
		PMA *t = Q.front(); Q.pop();
		for(int c = 'A'; c<='Z'; c++)
		{
			if(t->next[c])
			{
				Q.push(t->next[c]);
				PMA *r = t->next[0];
				while(!r->next[c]) r = r->next[0];
				t->next[c]->next[0] = r->next[c];
			}
		}
	}

	return root;
}

int match(char t, PMA* v, int &ret)
{
	int r=v->n;

	char c=t;
	while(!v->next[c]) v = v->next[0];
	v = v->next[c];
	r = v->n;
	ret += v->accept.size();

	return r;
}

void makeacpt(PMA* p, int n, string w)
{
	PMA *t = p;
	for(int j=0; j<w.size(); j++)
	{
		char c=w[j];
		if(t->next[c]==NULL) return;
		t = t->next[c];
	}

	for(int i=0; i<t->accept.size(); i++)
		if(t->accept[i]==n) return;

	t->accept.push_back(n);
}

class State
{
public:
	int x,y,pma,c;
	State(int x, int y, int pma, int c)
		:x(x),y(y),pma(pma),c(c)
	{}
};

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

bool v[60][60][60];
char dir[4]={'L', 'U', 'R', 'D'};

int main()
{
	int M,N;
	while(cin >> N >> M, (M||N))
	{
		memset(v,0,sizeof(v));

		int sx,sy;
		char f[90][90];
		for(int i=0; i<N; i++)
		for(int j=0; j<M; j++)
		{
			cin >> f[j][i];
			if(f[j][i]=='S')
			{
				sx=j;
				sy=i;
			}
		}

		int P;
		cin >> P;
		vector<string> str;
		for(int i=0; i<P; i++)
		{
			string s;
			cin >> s;
			str.push_back(s);
		}

		vector<PMA*> vpma;
		PMA* root = buildPMA(str,vpma,str.size());
		for(int j=0; j<str.size(); j++)
		for(int i=0; i<Psz; i++)
		{
			PMA* p=vpma[i];
			makeacpt(p,j,str[j]);
		}

		bool g=false;
		queue<State> q;
		q.push(State(sx,sy,0,0));

		while(!q.empty())
		{
			State s=q.front(); q.pop();
			if(v[s.x][s.y][s.pma]) continue;
			v[s.x][s.y][s.pma]=1;

			if(f[s.x][s.y]=='G')
			{
				g=true;
				cout << s.c << endl;
				break;
			}

			for(int i=0; i<4; i++)
			{
				int tx=s.x+dx[i], ty=s.y+dy[i];
				if(tx<0||ty<0||tx>=M||ty>=N) continue;
				if(f[tx][ty]=='#') continue;

				int ret=0;
				int tpma = match(dir[i],vpma[s.pma],ret);

				if(ret!=0) continue;
				if(v[tx][ty][tpma]) continue;

				q.push(State(tx,ty,tpma,s.c+1));


			}

		}

		if(!g) cout << -1 << endl;
	}
}