#include <bits/stdc++.h>
using namespace std;
void lwr(string& s) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] >= 'A' and s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  }
}
pair<int, int> _rank(const string& s) {
  int ret = 0;
  for (int i = 0; i < s.size(); i++) ret += s[i] == 'r';
  return pair<int, int>(ret, (int)s.size());
}
map<string, int> who;
const int N = 300010;
pair<int, int> val[N];
vector<int> g[N], gt[N];
int vis[N];
int c[N];
vector<int> ts;
void dfs(int u) {
  vis[u] = 1;
  for (int v : g[u])
    if (!vis[v]) dfs(v);
  ts.push_back(u);
}
pair<int, int> valc[N];
void dfst(int u, int cmp) {
  vis[u] = 2;
  c[u] = cmp;
  valc[cmp] = min(valc[cmp], val[u]);
  for (int v : gt[u])
    if (vis[v] != 2) dfst(v, cmp);
}
vector<int> gc[N];
pair<int, int> best[N];
pair<int, int> solve(int u) {
  if (best[u].first != 0x3f3f3f3f) return best[u];
  best[u] = valc[u];
  for (int v : gc[u]) best[u] = min(best[u], solve(v));
  return best[u];
}
int main() {
  ios::sync_with_stdio(0);
  int m, cnt = 0;
  cin >> m;
  vector<int> vv;
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    lwr(s);
    if (!who.count(s)) {
      who[s] = cnt;
      val[cnt] = _rank(s);
      cnt++;
    }
    vv.push_back(who[s]);
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string u, v;
    cin >> u >> v;
    lwr(u);
    lwr(v);
    if (!who.count(u)) {
      who[u] = cnt;
      val[cnt] = _rank(u);
      cnt++;
    }
    if (!who.count(v)) {
      who[v] = cnt;
      val[cnt] = _rank(v);
      cnt++;
    }
    int uu = who[u], vv = who[v];
    g[uu].push_back(vv);
    gt[vv].push_back(uu);
  }
  for (int i = 0; i < cnt; i++) {
    if (!vis[i]) dfs(i);
  }
  int comp = 0;
  fill(valc, valc + N, pair<int, int>(0x3f3f3f3f, 0x3f3f3f3f));
  for (int i = cnt - 1; i >= 0; i--) {
    if (vis[ts[i]] != 2) dfst(ts[i], comp++);
  }
  for (int u = 0; u < cnt; u++) {
    for (int v : g[u]) {
      if (c[u] != c[v]) gc[c[u]].push_back(c[v]);
    }
  }
  fill(best, best + N, pair<int, int>(0x3f3f3f3f, 0x3f3f3f3f));
  pair<long long, long long> ans(0LL, 0LL);
  for (int i = 0; i < m; i++) {
    pair<int, int> ret = solve(c[vv[i]]);
    ans.first += ret.first;
    ans.second += ret.second;
  }
  cout << ans.first << " " << ans.second << '\n';
  return 0;
}
