#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7, M = N;
struct ADJ {
  int head[N], nxt[M], to[M], n, ne;
  void add_edge(int f, int t) {
    to[ne] = t;
    nxt[ne] = head[f];
    head[f] = ne++;
  }
  void init(int nNodes) {
    ne = 0;
    n = nNodes;
    memset(head, -1, n * sizeof head[0]);
  }
};
struct SCC {
  ADJ *adj;
  ADJ dag;
  int visidx[N], lowlink[N], cmp[N], stck[N], stcksz, cmpCnt, dfst;
  void condense() {
    dag.init(cmpCnt);
    for (int u = 0; u < adj->n; ++u)
      for (int e = (*adj).head[u], v; ~e && (v = (*adj).to[e], 1);
           e = (*adj).nxt[e]) {
        if (cmp[u] != cmp[v]) dag.add_edge(cmp[u], cmp[v]);
      }
  }
  int operator[](int i) { return cmp[i]; }
  void operator()() {
    int n = adj->n;
    memset(visidx, -1, n * sizeof visidx[0]);
    memset(lowlink, -1, n * sizeof lowlink[0]);
    memset(cmp, -1, n * sizeof cmp[0]);
    cmpCnt = dfst = stcksz = 0;
    for (int i = 0; i < n; i++) {
      if (visidx[i] == -1) dfs(i);
    }
    condense();
  }
  void dfs(int u) {
    visidx[u] = lowlink[u] = dfst++;
    stck[stcksz++] = u;
    for (int e = (*adj).head[u], v; ~e && (v = (*adj).to[e], 1);
         e = (*adj).nxt[e]) {
      if (visidx[v] == -1) {
        dfs(v);
        lowlink[u] = min(lowlink[u], lowlink[v]);
      } else if (cmp[v] == -1)
        lowlink[u] = min(lowlink[u], visidx[v]);
    }
    if (lowlink[u] == visidx[u]) {
      do {
        cmp[stck[--stcksz]] = cmpCnt;
      } while (stck[stcksz] != u);
      ++cmpCnt;
    }
  }
};
struct TRIE {
  int nNodes;
  int nxt[N][26], idx[N];
  int wordCnt = 0;
  int Rs[N], len[N];
  void clear() {
    wordCnt = nNodes = 0;
    createNode();
  }
  int createNode() {
    memset(nxt[nNodes], -1, sizeof nxt[nNodes]);
    idx[nNodes] = -1;
    return nNodes++;
  }
  int operator[](const string &v) {
    int u = 0;
    int r = 0;
    for (auto c : v) {
      c = tolower(c) - 'a';
      if (c == 'r' - 'a') r++;
      if (!~nxt[u][c]) nxt[u][c] = createNode();
      u = nxt[u][c];
    }
    if (~idx[u]) return idx[u];
    len[wordCnt] = v.length();
    Rs[wordCnt] = r;
    return idx[u] = wordCnt++;
  }
};
int n, m;
int from[N], to[N], essay[N];
TRIE trie;
ADJ adj;
SCC scc;
pair<int, int> cmpInitial[N];
pair<int, int> dp[N];
int dpVis[N];
pair<int, int> dps(int u) {
  pair<int, int> &ret = dp[u];
  if (dpVis[u]) return ret;
  dpVis[u] = 1;
  ret = cmpInitial[u];
  for (int e = (scc.dag).head[u], v; ~e && (v = (scc.dag).to[e], 1);
       e = (scc.dag).nxt[e]) {
    ret = min(ret, dps(v));
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  trie.clear();
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string v;
    cin >> v;
    essay[i] = trie[v];
  }
  cin >> m;
  for (int j = 0; j < m; ++j) {
    string u, v;
    cin >> u >> v;
    from[j] = trie[u];
    to[j] = trie[v];
  }
  adj.init(trie.wordCnt);
  for (int j = 0; j < m; ++j) {
    adj.add_edge(from[j], to[j]);
  }
  scc.adj = &adj;
  scc();
  memset(cmpInitial, '?', sizeof cmpInitial);
  for (int i = 0; i < adj.n; ++i) {
    pair<int, int> &cur = cmpInitial[scc[i]];
    cur = min(cur, pair<int, int>{trie.Rs[i], trie.len[i]});
  }
  long long R = 0, L = 0;
  for (int i = 0; i < n; ++i) {
    pair<int, int> ret = dps(scc[essay[i]]);
    R += ret.first, L += ret.second;
  }
  cout << R << " " << L << '\n';
}
