#include <bits/stdc++.h>
const int N = 100010;
const int INF = 1e9;
std::string s[N], a[N], b[N], v[N << 1];
std::vector<int> ed[N], ev[N], scc[N], sed[N];
int cnt[N], vis[N], id[N], stack[N], best_l[N], best_r[N];
void tolower(std::string& s) {
  for (int i = 0; i < int(s.size()); ++i)
    if ('A' <= s[i] && s[i] <= 'Z') {
      s[i] += 32;
    }
}
int count(const std::string& s) {
  int r = 0;
  for (int i = 0; i < int(s.size()); ++i) {
    r += s[i] == 'r';
  }
  return r;
}
void dfs(int u, int& st_sz) {
  if (vis[u]) return;
  vis[u] = 1;
  for (int i = 0; i < int(ed[u].size()); ++i) {
    dfs(ed[u][i], st_sz);
  }
  stack[++st_sz] = u;
}
void dfs_rev(int u, int k) {
  if (vis[u]) return;
  vis[u] = 1;
  id[u] = k;
  scc[k].push_back(u);
  for (int i = 0; i < int(ev[u].size()); ++i) {
    dfs_rev(ev[u][i], k);
  }
}
void dfs_scc(int u) {
  if (vis[u]) return;
  vis[u] = 1;
  for (int i = 0; i < int(sed[u].size()); ++i) {
    int v = sed[u][i];
    dfs_scc(v);
    if (best_r[v] < best_r[u] ||
        (best_r[v] == best_r[u] && best_l[v] < best_l[u])) {
      best_r[u] = best_r[v];
      best_l[u] = best_l[v];
    }
  }
}
int main() {
  int m;
  std::cin >> m;
  for (int i = 1; i <= m; ++i) {
    std::cin >> s[i];
    tolower(s[i]);
  }
  int n;
  std::cin >> n;
  int vn = 0;
  for (int i = 1; i <= n; ++i) {
    std::cin >> a[i] >> b[i];
    tolower(a[i]);
    tolower(b[i]);
    v[++vn] = a[i];
    v[++vn] = b[i];
  }
  std::sort(v + 1, v + vn + 1);
  vn = std::unique(v + 1, v + vn + 1) - v - 1;
  for (int i = 1; i <= vn; ++i) {
    cnt[i] = count(v[i]);
  }
  for (int i = 1; i <= n; ++i) {
    int aid = std::lower_bound(v + 1, v + vn + 1, a[i]) - v;
    int bid = std::lower_bound(v + 1, v + vn + 1, b[i]) - v;
    ed[aid].push_back(bid);
    ev[bid].push_back(aid);
  }
  int st_sz = 0;
  for (int i = 1; i <= vn; ++i) {
    dfs(i, st_sz);
  }
  int scc_cnt = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = st_sz; i >= 1; --i) {
    int u = stack[i];
    if (!vis[u]) {
      dfs_rev(u, ++scc_cnt);
    }
  }
  for (int i = 1; i <= scc_cnt; ++i) {
    int l = INF, r = INF;
    for (int j = 0; j < int(scc[i].size()); ++j) {
      int u = scc[i][j];
      if (cnt[u] < r || (cnt[u] == r && v[u].size() < l)) {
        r = cnt[u];
        l = v[u].size();
      }
      for (int k = 0; k < int(ed[u].size()); ++k) {
        int v = ed[u][k];
        if (id[v] != i) {
          sed[i].push_back(id[v]);
        }
      }
    }
    best_l[i] = l;
    best_r[i] = r;
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= scc_cnt; ++i) {
    std::sort(sed[i].begin(), sed[i].end());
    sed[i].erase(std::unique(sed[i].begin(), sed[i].end()), sed[i].end());
  }
  for (int i = 1; i <= scc_cnt; ++i) {
    dfs_scc(i);
  }
  long long ans = 0, r = 0;
  for (int i = 1; i <= m; ++i) {
    int u = std::lower_bound(v + 1, v + vn + 1, s[i]) - v;
    if (s[i] == v[u]) {
      ans += best_l[id[u]];
      r += best_r[id[u]];
    } else {
      ans += s[i].size();
      r += count(s[i]);
    }
  }
  std::cout << r << ' ' << ans;
}
