#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, inf = 1e9 + 7;
long long n, k, i, j, cnt, cur;
pair<long long, long long> c[N];
map<string, long long> m;
priority_queue<pair<pair<long long, long long>, long long> > pq;
vector<long long> adj[N], u;
string s;
inline long long in() {
  cin >> s;
  transform(s.begin(), s.end(), s.begin(), ::tolower);
  if (!m[s])
    m[s] = ++cnt, c[m[s]] = pair<long long, long long>(
                      -count(s.begin(), s.end(), 'r'), -(long long)s.size());
  return m[s];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, a, b, v;
  pair<long long, long long> it;
  cin >> n;
  for (i = 0; i < n; i++) u.emplace_back(in());
  cin >> k;
  while (k--) {
    a = in();
    b = in();
    adj[b].emplace_back(a);
  }
  for (i = 1; i < cnt + 1; i++)
    pq.push(pair<pair<long long, long long>, long long>(c[i], i));
  while (!pq.empty()) {
    v = pq.top().second;
    it = pq.top().first;
    pq.pop();
    if (c[v] != it) continue;
    for (auto i : adj[v])
      if (it > c[i]) {
        c[i] = it;
        pq.push(pair<pair<long long, long long>, long long>(c[i], i));
      }
  }
  pair<long long, long long> ans = pair<long long, long long>(0, 0);
  for (auto i : u) ans.first -= c[i].first, ans.second -= c[i].second;
  cout << ans.first << " " << ans.second;
}
