#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5 * 1000 * 100 + 10;
map<string, long long> mp;
long long Cr[maxn], len[maxn], n, m, cnt;
bool mark[maxn];
string s;
vector<long long> e[maxn], sources;
long long change(string &s) {
  long long an = 0;
  for (int j = 0; j < s.size(); j++) {
    if (s[j] < 'a') s[j] = s[j] - 'A' + 'a';
    if (s[j] == 'r') an++;
  }
  if (mp.find(s)->second == 0) mp[s] = cnt, cnt++;
  long long p = mp[s];
  Cr[p] = an;
  len[p] = s.size();
  return p;
}
void input() {
  cin >> n;
  cnt = 1;
  for (int o = 0; o < n; o++) cin >> s, sources.push_back(change(s));
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s;
    long long u = change(s);
    cin >> s;
    long long v = change(s);
    e[u].push_back(v);
  }
}
inline void dfs(long long source) {
  mark[source] = true;
  for (int i = 0; i < e[source].size(); i++) {
    if (!mark[e[source][i]]) dfs(e[source][i]);
    if (Cr[source] < Cr[e[source][i]]) continue;
    if (Cr[source] == Cr[e[source][i]]) {
      len[source] = min(len[source], len[e[source][i]]);
      continue;
    }
    Cr[source] = Cr[e[source][i]];
    len[source] = len[e[source][i]];
  }
}
void work() {
  for (int i = 0; i < sources.size(); i++)
    if (!mark[sources[i]]) dfs(sources[i]);
  memset(mark, 0, sizeof mark);
  for (int i = 0; i < sources.size(); i++)
    if (!mark[sources[i]]) dfs(sources[i]);
  long long r_ans = 0;
  long long l_ans = 0;
  for (int i = 0; i < sources.size(); i++)
    r_ans += Cr[sources[i]], l_ans += len[sources[i]];
  cout << r_ans << " " << l_ans;
}
int main() {
  input();
  work();
  return 0;
}
