#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
map<string, int> mp;
string s[maxn];
vector<int> G[maxn];
struct node {
  int u, val, len;
  node(int a, int b, int c) { u = a, val = b, len = c; }
  bool operator<(const node& t) const {
    if (val != t.val) return val > t.val;
    return len > t.len;
  }
};
int val[maxn], len[maxn], vis[maxn], cnt, n;
priority_queue<node> q;
int gao(int cur) {
  for (int i = 0; i < s[cur].length(); i++)
    if (s[cur][i] >= 'A' && s[cur][i] <= 'Z') s[cur][i] = s[cur][i] - 'A' + 'a';
  if (!mp[s[cur]]) {
    mp[s[cur]] = ++cnt;
    for (int i = 0; i < s[cur].length(); i++)
      if (s[cur][i] == 'r') val[cnt]++;
    len[cnt] = s[cur].length();
    q.push(node(cnt, val[cnt], len[cnt]));
  }
  return mp[s[cur]];
}
void dij() {
  while (!q.empty()) {
    int u = q.top().u;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (auto v : G[u])
      if (val[v] > val[u] || (val[v] == val[u] && len[v] > len[u])) {
        val[v] = val[u];
        len[v] = len[u];
        q.push(node(v, val[v], len[v]));
      }
  }
}
int main() {
  int m;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    gao(i);
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> s[n + 1];
    int u = gao(n + 1);
    cin >> s[n + 1];
    int v = gao(n + 1);
    G[v].push_back(u);
  }
  dij();
  int ans1 = 0;
  long long ans2 = 0;
  for (int i = 1; i <= n; i++) {
    int u = mp[s[i]];
    ans1 += val[u];
    ans2 += len[u];
  }
  cout << ans1 << " " << ans2;
}
