#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 15;
const int maxm = 1e6 + 15;
map<string, int> dic;
vector<pair<int, int> > a;
vector<int> b;
vector<int> G[maxn];
void convert(string &s) {
  for (int j = 0; j < s.size(); j++) s[j] = tolower(s[j]);
}
int tot = 0;
void add(string &s) {
  convert(s);
  if (dic.count(s)) {
    b.push_back(dic[s]);
    return;
  }
  dic[s] = tot++;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == 'r') cnt++;
  a.push_back(pair<int, int>(cnt, s.size()));
  b.push_back(dic[s]);
}
int inq[maxn];
int main() {
  ios::sync_with_stdio(false);
  int m;
  cin >> m;
  string s;
  for (int i = 1; i <= m; i++) {
    cin >> s;
    add(s);
  }
  string u, v;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> u >> v;
    add(u);
    add(v);
    G[dic[v]].push_back(dic[u]);
  }
  queue<int> que;
  for (int i = 0; i < dic.size(); i++) que.push(i), inq[i] = 1;
  while (que.size()) {
    int u = que.front();
    que.pop();
    inq[u] = 0;
    for (int v : G[u]) {
      if (a[v] > a[u]) {
        a[v] = a[u];
        if (inq[v]) continue;
        inq[v] = 1;
        que.push(v);
      }
    }
  }
  long long ans1 = 0, ans2 = 0;
  for (int i = 0; i < m; i++) {
    ans1 += a[b[i]].first, ans2 += a[b[i]].second;
  }
  cout << ans1 << ' ' << ans2 << endl;
  return 0;
}
