#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long MOD = 1000000007, N = 200005;
string tab[N], to_word[N];
long long idx, nb[N], k;
pair<long long, long long> dp[N], mini[N];
map<string, long long> mymap;
vector<vector<long long> > vec, res, con;
vector<long long> comp, order;
bool vis[N];
void dfs(long long node) {
  vis[node] = 1;
  for (auto it : vec[node])
    if (!vis[it]) dfs(it);
  order.push_back(node);
}
void dfs2(long long node) {
  vis[node] = 0, nb[node] = k;
  for (auto it : res[node])
    if (vis[it]) dfs2(it);
}
pair<long long, long long> solve(long long node) {
  if (dp[node] != pair<long long, long long>(-1, -1)) return dp[node];
  pair<long long, long long> ans = mini[node];
  for (auto it : con[node]) {
    pair<long long, long long> t = solve(it);
    if ((t.first < ans.first) ||
        ((t.first == ans.first) && (t.second < ans.second)))
      ans = t;
  }
  return dp[node] = ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof dp);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> tab[i];
    for (auto &it : tab[i])
      if (it <= 'Z') it = 'a' + (it - 'A');
    if (mymap.find(tab[i]) == mymap.end())
      to_word[idx] = tab[i], mymap[tab[i]] = idx++;
  }
  vector<pair<long long, long long> > edges;
  long long m;
  cin >> m;
  while (m--) {
    string a, b;
    cin >> a >> b;
    for (auto &it : a)
      if (it <= 'Z') it = 'a' + (it - 'A');
    for (auto &it : b)
      if (it <= 'Z') it = 'a' + (it - 'A');
    if (mymap.find(a) == mymap.end()) to_word[idx] = a, mymap[a] = idx++;
    if (mymap.find(b) == mymap.end()) to_word[idx] = b, mymap[b] = idx++;
    edges.push_back(pair<long long, long long>(mymap[a], mymap[b]));
  }
  vec.resize(idx), res.resize(idx);
  for (auto it : edges)
    vec[it.first].push_back(it.second), res[it.second].push_back(it.first);
  for (long long i = 0; i < idx; ++i)
    if (!vis[i]) dfs(i);
  reverse((order).begin(), (order).end());
  for (long long i = 0; i < idx; ++i)
    if (vis[order[i]] == 1) dfs2(order[i]), k++;
  con.resize(k);
  for (long long i = 0; i < idx; ++i)
    mini[i] = pair<long long, long long>(1000000000, 1000000000);
  for (long long i = 0; i < idx; ++i) {
    long long r = 0;
    for (auto it : to_word[i]) r += (it == 'r');
    if ((mini[nb[i]].first > r) ||
        ((mini[nb[i]].first == r) &&
         ((long long)to_word[i].size() < mini[nb[i]].second)))
      mini[nb[i]] = pair<long long, long long>(r, (long long)to_word[i].size());
    for (auto it : vec[i])
      if (nb[it] != nb[i]) con[nb[i]].push_back(nb[it]);
  }
  pair<long long, long long> ans = pair<long long, long long>(0, 0);
  for (long long i = 0; i < n; ++i) {
    pair<long long, long long> t = solve(nb[mymap[tab[i]]]);
    ans =
        pair<long long, long long>(ans.first + t.first, ans.second + t.second);
  }
  cout << ans.first << " " << ans.second;
  return 0;
}
