using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static readonly int[][] di1=new int[][]{new int[]{-1,0},new int[]{1,0},new int[]{0,-1},new int[]{0,1}};
	static void Main(){
		Sc sc=new Sc();
		var ho=new int[18];
		var hg=new char[]{'U','D','L','R'};
		ho['D'-'D']=1;ho['L'-'D']=2;ho['R'-'D']=3;
		StringBuilder sb=new StringBuilder();
		int[] s=sc.Ia;
		while(s[0]!=0){
			int h=s[0],w=s[1];
			char c='#';
			int sy=0,sx=0,gy=0,gx=0;
			var bm=new char[h+2][];
			var b=new bool[h+2][][];
			var qu=new Queue<Tuple<int,int,int,int>>();
			for(int i = 1;i<=h;i++) {
				bm[i]=(c+sc.S+c).ToCharArray();
				for(int j = 0;j<w+2;j++) {
					if(bm[i][j]=='S'){sy=i;sx=j;}
					else if(bm[i][j]=='G'){gy=i;gx=j;}
				}
			}
			bm[0]=bm[h+1]=new string(c,w+2).ToCharArray();
			int q=sc.I;
			var t=new string[q];
			for(int i = 0;i<q;i++) {t[i]=sc.S;}
			Ac ac=new Ac(q!=0?t:new string[]{"F"},'D','U');
			
			for(int i = 1;i<=h;i++) {
				b[i]=new bool[w+2][];
				for(int j = 0;j<w+2;j++) {b[i][j]=new bool[ac.cnt];}
			}

			qu.Enqueue(Tuple.Create(sy,sx,1,0));
			for(int i = 0;i<ac.cnt;i++) {b[sy][sx][i]=true;}
	
			int ans=0;
			while(qu.Count>0){
				var e=qu.Dequeue();
				if(e.Item1==gy&&e.Item2==gx){
					ans=e.Item3-1;
					break;
				}
				Fdi(e.Item1,e.Item2,(y,x,i)=>{
					if(bm[y][x]!='#'){
						int d=ac.Av(e.Item4,hg[i]);
						if(!ac.h[d].stl&&!b[y][x][d]){
							qu.Enqueue(Tuple.Create(y,x,e.Item3+1,d));
							b[y][x][d]=true;
						}
					}
				});
			}
			sb.Append((ans==0?-1:ans)+"\n");
			s=sc.Ia;
		}
		Console.Write(sb);
	}
	static void Fdi(int y,int x,Action<int,int,int> f){for(int i=0;i<4;i++){f(y+di1[i][0],x+di1[i][1],i);}}
}
public class Ac{
	static private int o;
	private Nd root;
	public int n,cnt=1;
	public Nd[] h;
	public Nd[] q;
	public class Nd{
		public Nd[] ar;
		public List<Nd> li=new List<Nd>();
		public Nd sx;
		public bool stl=false;
		public int c,l=0,n;
		public bool b=false;
		public Nd(int c,int l){this.c=c-o;this.l=l;}
	}
	public Ac(string[] t,int a,int z){
		n=z-a+1;
		o=a;
		root=new Nd(a-1,0);
		q=new Nd[t.Length];
		for(int i = 0;i<t.Length;i++) {
			var r=root;
			for(int j = 0;j<t[i].Length;j++) {
				if(!r.b){r.ar=new Nd[n];r.b=true;}
				if(r.ar[t[i][j]-o]==null){r.li.Add(r=r.ar[t[i][j]-o]=new Nd(t[i][j],j+1));cnt++;}
				else{r=r.ar[t[i][j]-o];}
			}
			q[i]=r;
			r.stl=true;
		}
		h=new Nd[cnt];
		h[0]=root;
		int p=1;
		var qu=new Queue<Nd>();
		for(int i = 0;i<root.li.Count;i++,p++) {
			root.li[i].sx=root;
			if(root.li[i].b){qu.Enqueue(root.li[i]);}
			root.li[i].n=p;
			h[p]=root.li[i];
		}
		while(qu.Count>0){
			var e=qu.Dequeue();
			for(int i = 0;i<e.li.Count;i++,p++) {
				var r=e.sx;
				while(r!=null&&(!r.b||r.ar[e.li[i].c]==null)){r=r.sx;}
				e.li[i].sx=r!=null?r.ar[e.li[i].c]:root;
				if(e.li[i].sx.stl){e.li[i].stl=true;}
				if(e.li[i].b){qu.Enqueue(e.li[i]);}
				e.li[i].n=p;
				h[p]=e.li[i];
			}
		}
	}
	public void Match(string t,bool bo,Action<int,Nd> f){
		var e=root;
		for(int i = 0;i<t.Length;i++) {
			while(e!=root&&(!e.b||e.ar[t[i]-o]==null)){e=e.sx;}
			if(e.ar[t[i]-o]!=null){e=e.ar[t[i]-o];}
			if(bo||e.stl){f(i,e);}
		}
	}
	public int Av(int n,char c){
		var e=h[n];
		while(e!=root&&(!e.b||e.ar[c-o]==null)){e=e.sx;}
		if(e.ar[c-o]!=null){e=e.ar[c-o];}
		return e.n;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 23968