#include <bits/stdc++.h>
using namespace std;
struct edge {
  int n, p;
  void var(int _n, int _p) { n = _n, p = _p; }
} edges[200005], edges_[200005];
bool vis[200005], ins[200005];
int n, m, g[200005], edgeSize, g_[200005], edgeSize_, cnt, nodes[200005][2];
int dp[200005][2];
int dfn[200005], low[200005], dfsClock, sccCnt, sccNo[200005], s[200005], top;
string essay[200005];
map<string, int> match;
inline int countR(string& x) {
  int ret = 0;
  for (int i = 0; i < x.length(); ++i)
    if (x[i] == 'r') ret++;
  return ret;
}
inline bool betterThan(string& a, string& b) {
  if (countR(a) != countR(b)) return countR(a) < countR(b);
  return a.length() < b.length();
}
inline char toLower(char x) {
  if (x >= 'A' && x <= 'Z') return x - 'A' + 'a';
  return x;
}
int insertNode(string& x) {
  if (match.find(x) == match.end()) {
    match.insert(pair<string, int>(x, ++cnt));
    nodes[cnt][0] = x.length();
    nodes[cnt][1] = countR(x);
    return cnt;
  }
  return match[x];
}
void addEdge(int a, int b) {
  edges[++edgeSize].var(b, g[a]);
  g[a] = edgeSize;
}
void addEdge_(int a, int b) {
  edges_[++edgeSize_].var(b, g_[a]);
  g_[a] = edgeSize_;
}
void tarjan(int x) {
  int p, v;
  low[x] = dfn[x] = ++dfsClock;
  s[++top] = x;
  ins[x] = true;
  for (p = g[x]; p; p = edges[p].p) {
    v = edges[p].n;
    if (!dfn[v]) {
      tarjan(v);
      low[x] = min(low[x], low[v]);
    } else if (ins[v])
      low[x] = min(low[x], dfn[v]);
  }
  if (low[x] == dfn[x]) {
    sccCnt++;
    while (top && s[top] != x) {
      sccNo[s[top--]] = sccCnt;
      ins[s[top + 1]] = false;
    }
    ins[s[top--]] = false;
    sccNo[x] = sccCnt;
  }
}
void dfs(int x) {
  if (vis[x]) return;
  int v, p;
  vis[x] = true;
  for (p = g_[x]; p; p = edges_[p].p) {
    v = edges_[p].n;
    dfs(v);
    if (dp[x][1] > dp[v][1] || (dp[x][1] == dp[v][1] && dp[x][0] > dp[v][0]))
      dp[x][0] = dp[v][0], dp[x][1] = dp[v][1];
  }
}
int main() {
  int i, j, p;
  long long int ansLen = 0, ansR = 0;
  string temp1, temp2;
  ios_base ::sync_with_stdio(false);
  cin >> m;
  for (i = 1; i <= m; ++i) {
    cin >> essay[i];
    for (j = 0; j < essay[i].length(); ++j) essay[i][j] = toLower(essay[i][j]);
    insertNode(essay[i]);
  }
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> temp1 >> temp2;
    for (j = 0; j < temp1.length(); ++j) temp1[j] = toLower(temp1[j]);
    for (j = 0; j < temp2.length(); ++j) temp2[j] = toLower(temp2[j]);
    addEdge(insertNode(temp1), insertNode(temp2));
  }
  memset(dp, 0x3f, sizeof(dp));
  for (i = 1; i <= cnt; ++i)
    if (!dfn[i]) tarjan(i);
  for (i = 1; i <= cnt; ++i) {
    if (nodes[i][1] < dp[sccNo[i]][1] ||
        (nodes[i][1] == dp[sccNo[i]][1] && nodes[i][0] < dp[sccNo[i]][0]))
      dp[sccNo[i]][0] = nodes[i][0], dp[sccNo[i]][1] = nodes[i][1];
    for (p = g[i]; p; p = edges[p].p)
      if (sccNo[i] != sccNo[edges[p].n]) addEdge_(sccNo[i], sccNo[edges[p].n]);
  }
  for (i = 1; i <= sccCnt; ++i)
    if (!vis[i]) dfs(i);
  for (i = 1; i <= m; ++i)
    ansLen += dp[sccNo[match[essay[i]]]][0],
        ansR += dp[sccNo[match[essay[i]]]][1];
  cout << ansR << ' ' << ansLen << endl;
  return 0;
}
