#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

// D, R, U, L
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

// 文字の種類数をtemplate引数で渡す
template <int types = 26>
struct AhoCorasick {
  // trie木のnode
  struct node {
    node *fail;
    V<node*> next;
    V<int> matched;
    int idx;
    node() : fail(nullptr), next(types, nullptr) {}
    node(int idx) : fail(nullptr), next(types, nullptr), idx(idx) {}
  };

  // 辞書のサイズ, 頂点数
  int sz, nodesize;
  // trie木の根
  node *root;
  // vectorを結合
  V<int> unite(const V<int> &a, const V<int> &b) {
    V<int> ret;
    set_union(ALL(a), ALL(b), back_inserter(ret));
    return ret;
  }
  // 文字と数字の対応付けをする関数
  function<int(char)> trans;
  // 初期化
  AhoCorasick() {}
  AhoCorasick(V<string> pattern, function<int(char)> f = [](char c){return c-'a';}) {
    nodesize = 0;
    trans = f;
    build(pattern);
  }
  // 文字列集合patternからtrie木っぽいオートマトンを作成
  void build(V<string> pattern) {
    sz = pattern.size(), root = new node(nodesize++);
    node *now;
    root->fail = root;
    REP(i, sz) {
      now = root;
      for(const auto &c: pattern[i]) {
        if(now->next[trans(c)] == nullptr) {
          now->next[trans(c)] = new node(nodesize++);
        }
        now = now->next[trans(c)];
      }
      now->matched.PB(i);
    }

    queue<node*> que;
    REP(i, types) {
      if(root->next[i] == nullptr) {
        root->next[i] = root;
      } else {
        root->next[i]->fail = root;
        que.push(root->next[i]);
      }
    }
    while(que.size()) {
      now = que.front(); que.pop();
      REP(i, types) {
        if(now->next[i] != nullptr) {
          node *nxt = now->fail;
          while(!nxt->next[i]) nxt = nxt->fail;
          now->next[i]->fail = nxt->next[i];
          now->next[i]->matched = unite(now->next[i]->matched, nxt->next[i]->matched);
          que.push(now->next[i]);
        }
      }
    }
  }
  // 一文字ずつ照合していく
  node* next(node* p, const char c) {
    while(p->next[trans(c)] == nullptr) p = p->fail;
    return p->next[trans(c)];
  }
  // 文字列s中に辞書と一致する部分列がどれだけあるか
  V<int> match(const string s) {
    V<int> res(sz);
    node *now = root;
    for(auto c : s) {
      now = next(now, c);
      for(auto i : now->matched) res[i]++;
    }
    return res;
  }
};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  while(1) {
    int h, w;
    cin >> h >> w;
    if(!h) break;
    V<string> board(h);
    REP(i, h) cin >> board[i];
    int n;
    cin >> n;
    V<string> v(n);
    REP(i, n) cin >> v[i];

    int sx = -1, sy = -1, gx = -1, gy = -1;
    REP(i, h) REP(j, w) {
      if(board[i][j] == 'S') {
        sx = j, sy = i;
      } else if(board[i][j] == 'G') {
        gx = j, gy = i;
      }
    }

    char dir[4] = {'D', 'R', 'U', 'L'};
    auto trans = [&](char c) {
      if(c == 'D') return 0;
      else if(c == 'R') return 1;
      else if(c == 'U') return 2;
      else if(c == 'L') return 3;
    };
    AhoCorasick<4> aho(v, trans);
    // cout << "nodesize=" << aho.nodesize << endl;
    AhoCorasick<4>::node *now = aho.root;

    struct nt {
      int y, x;
      AhoCorasick<4>::node *node;
      nt(int x, int y, AhoCorasick<4>::node *n) : y(y), x(x) { node = n; }
    };

    // d[y][x][あほこらのnode] = 最小距離
    VVV<int> d(h, VV<int>(w, V<int>(aho.nodesize, INF)));
    queue<nt> que;
    d[sy][sx][0] = 0;
    que.push(nt(sx, sy, now));
    while(que.size()) {
      nt vec = que.front(); que.pop();
      // cout << vec.x << " " << vec.y << " " << vec.node->idx << endl;
      REP(i, 4) {
        int nx = vec.x + dx[i], ny = vec.y + dy[i];
        // cout << "nx=" << nx << " ny=" << ny << endl;
        if(!IN(0LL,w,nx) || !IN(0LL,h,ny) || board[ny][nx]=='#') continue;
        AhoCorasick<4>::node *next = aho.next(vec.node, dir[i]);
        if(next == nullptr) {
          continue;
        }
        // cout << next->matched << endl;
        if(next->matched.size()) continue;
        if(d[ny][nx][next->idx] > d[vec.y][vec.x][vec.node->idx] + 1) {
          d[ny][nx][next->idx] = d[vec.y][vec.x][vec.node->idx] + 1;
          que.push(nt(nx, ny, next));
        }
      }
    }

    int ret = INF;
    REP(i, aho.nodesize) chmin(ret, d[gy][gx][i]);
    if(ret == INF) cout << -1 << endl;
    else cout << ret << endl;
  }
 
  return 0;
}




Measured memory_bytes: 4948