#include <bits/stdc++.h>
using namespace std;
int n, m;
string s[300005];
vector<pair<pair<long long, long long>, int> > q;
map<string, int> mp;
char a[500005], b[500005];
vector<int> v[300005];
bool u[300005];
pair<long long, long long> ans[300005];
long long sum = 0, r = 0;
void dfs(int i, int now, int x, int y) {
  u[now] = 1;
  if (now >= 1 && now <= n) ans[now].first = x, ans[now].second = y;
  for (int j = 0; j < v[now].size(); j++)
    if (!u[v[now][j]]) dfs(i, v[now][j], x, y);
}
int main() {
  scanf("%d", &n);
  long long cnt = 0;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    cnt = 0;
    for (int j = 0; j < s[i].size(); j++) {
      if (s[i][j] >= 'A' && s[i][j] <= 'Z') s[i][j] += 'a' - 'A';
      if (s[i][j] == 'r') cnt++;
    }
    if (!mp[s[i]]) mp[s[i]] = i;
    q.push_back(make_pair(make_pair(cnt, (long long)s[i].size()), mp[s[i]]));
  }
  scanf("%d", &m);
  int k = n;
  for (int i = 1; i <= m; i++) {
    scanf("%s", a);
    scanf("%s", b);
    for (int j = 0; j < strlen(a); j++)
      if (a[j] >= 'A' && a[j] <= 'Z') a[j] += 'a' - 'A';
    if (!mp[a]) {
      k++;
      mp[a] = k;
    }
    cnt = 0;
    for (int j = 0; j < strlen(b); j++) {
      if (b[j] >= 'A' && b[j] <= 'Z') b[j] += 'a' - 'A';
      if (b[j] == 'r') cnt++;
    }
    if (!mp[b]) {
      k++;
      mp[b] = k;
      s[k] = b;
    }
    q.push_back(make_pair(make_pair(cnt, (long long)strlen(b)), mp[b]));
    v[mp[b]].push_back(mp[a]);
  }
  sort(q.begin(), q.end());
  for (int i = 0; i < q.size(); i++)
    if (!u[q[i].second])
      dfs(q[i].second, q[i].second, q[i].first.first, q[i].first.second);
  for (int i = 1; i <= n; i++)
    sum += ans[mp[s[i]]].second, r += ans[mp[s[i]]].first;
  cout << r << ' ' << sum << endl;
  return 0;
}
