#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 123;
int M, N, push, ar[maxn];
pair<int, int> val[maxn];
bool used[maxn];
vector<int> way[maxn];
map<string, int> ID;
priority_queue<pair<pair<int, int>, int> > pq;
int add(string &str) {
  int r = 0;
  for (unsigned int i = 0; i < str.size(); i++) {
    str[i] |= 32;
    r += str[i] == 'r';
  }
  if (ID[str]) return ID[str];
  ID[str] = ++push;
  val[push] = pair<int, int>(r, str.size());
  pq.push(pair<pair<int, int>, int>(pair<int, int>(-r, -str.size()), push));
  return push;
}
int main() {
  scanf("%d", &M);
  string a, b;
  for (int i = 1; i <= M; i++) {
    cin >> a;
    ar[i] = add(a);
  }
  scanf("%d", &N);
  for (int i = 1, x, y; i <= N; i++) {
    cin >> a >> b;
    x = add(a);
    y = add(b);
    way[y].push_back(x);
  }
  while (!pq.empty()) {
    int node = pq.top().second;
    pq.pop();
    if (used[node]) continue;
    used[node] = 1;
    for (int i = 0, adj; i < (int)way[node].size(); i++) {
      adj = way[node][i];
      if (val[node] < val[adj]) {
        val[adj] = val[node];
        pq.push(pair<pair<int, int>, int>(
            pair<int, int>(-val[node].first, -val[node].second), adj));
      }
    }
  }
  long long int ans1 = 0, ans2 = 0;
  for (int i = 1; i <= M; i++) {
    ans1 += val[ar[i]].first;
    ans2 += val[ar[i]].second;
  }
  printf("%I64d %I64d\n", ans1, ans2);
  return 0;
}
