#include <bits/stdc++.h>
using namespace std;
int N, M;
string W[200000];
map<string, int> mp;
string F[200000], T[200000];
signed long long sc[400000];
vector<int> E[300000];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> W[i];
    for (__typeof(W[i].begin()) it = W[i].begin(); it != W[i].end(); it++)
      *it = tolower(*it);
    mp[W[i]] = 0;
  }
  cin >> M;
  for (i = 0; i < M; i++) {
    cin >> F[i] >> T[i];
    for (__typeof(F[i].begin()) it = F[i].begin(); it != F[i].end(); it++)
      *it = tolower(*it);
    for (__typeof(T[i].begin()) it = T[i].begin(); it != T[i].end(); it++)
      *it = tolower(*it);
    mp[F[i]] = mp[T[i]] = 0;
  }
  i = 0;
  for (__typeof(mp.begin()) it = mp.begin(); it != mp.end(); it++) {
    it->second = i;
    sc[i] = 10000000LL * count(it->first.begin(), it->first.end(), 'r') +
            it->first.size();
    i++;
  }
  for (i = 0; i < M; i++) E[mp[T[i]]].push_back(mp[F[i]]);
  priority_queue<pair<signed long long, int> > Q;
  for (i = 0; i < mp.size(); i++) Q.push(make_pair(-sc[i], i));
  while (!Q.empty()) {
    signed long long s = -Q.top().first;
    int k = Q.top().second;
    Q.pop();
    if (s != sc[k]) continue;
    for (i = 0; i < E[k].size(); i++) {
      int tar = E[k][i];
      if (sc[tar] > sc[k]) {
        sc[tar] = sc[k];
        Q.push(make_pair(-sc[tar], tar));
      }
    }
  }
  signed long long tr = 0, tl = 0;
  for (i = 0; i < N; i++) {
    signed long long s = sc[mp[W[i]]];
    tr += s / 10000000;
    tl += s % 10000000;
  }
  (void)printf("%lld %lld\n", tr, tl);
}
int main(int argc, char **argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false);
  for (i = 0; i < argc - 1; i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}
