#include <bits/stdc++.h>
using namespace std;
long long bl[1001001], n, an[1001001], a1, a2, m, num;
string s[1001001], a, b, aa[1001001], bb[1001001];
map<string, long long> mp, is;
vector<long long> g[1001001];
struct node {
  long long len, ans;
  string b;
  bool operator<(const node &s) const {
    return ans < s.ans || (ans == s.ans && len < s.len);
  }
} t[1001001];
void dfs(long long u, long long fa) {
  bl[u] = fa;
  for (long long i = 0; i < g[u].size(); i++) {
    long long v = g[u][i];
    if (bl[v] != 0) continue;
    dfs(v, fa);
  }
}
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    cin >> s[i];
    for (long long j = 0; j < s[i].size(); j++) {
      if (s[i][j] < 97) s[i][j] += 32;
      if (s[i][j] == 'r') an[i]++;
    }
  }
  scanf("%lld", &m);
  for (long long i = 1; i <= m; i++) {
    cin >> a >> b;
    long long ansa = 0;
    for (long long j = 0; j < a.size(); j++) {
      if (a[j] < 97) a[j] += 32;
      if (a[j] == 'r') ansa++;
    }
    long long ansb = 0;
    for (long long j = 0; j < b.size(); j++) {
      if (b[j] < 97) b[j] += 32;
      if (b[j] == 'r') ansb++;
    }
    aa[i] = a;
    bb[i] = b;
    if (mp[b] == 0) {
      num++;
      mp[b] = num;
      t[num].b = b;
      t[num].len = b.size();
      t[num].ans = ansb;
    }
    if (mp[a] == 0) {
      num++;
      mp[a] = num;
      t[num].b = a;
      t[num].len = a.size();
      t[num].ans = ansa;
    }
  }
  sort(t + 1, t + num + 1);
  for (long long i = 1; i <= num; i++) is[t[i].b] = i;
  for (long long i = 1; i <= m; i++) g[is[bb[i]]].push_back(is[aa[i]]);
  for (long long i = 1; i <= num; i++)
    if (bl[i] == 0) dfs(i, i);
  for (long long i = 1; i <= n; i++) {
    long long num = is[s[i]];
    if (num == 0) {
      a1 += an[i];
      a2 += s[i].size();
    } else {
      a1 += t[bl[num]].ans;
      a2 += t[bl[num]].len;
    }
  }
  cout << a1 << ' ' << a2;
  return 0;
}
