#include <bits/stdc++.h>
using namespace std;
int m, n;
string s[700005];
string s1[700005][2];
vector<int> adj[700005];
pair<long long int, long long int> ans[700005];
int vis[700005];
string convert(string ss) {
  for (int i = 0; i < ss.length(); ++i) {
    if (ss[i] >= 'A' && ss[i] <= 'Z') ss[i] += 32;
  }
  return ss;
}
long long int countr(string ss) {
  long long int c = 0;
  for (int i = 0; i < ss.length(); ++i) {
    if (ss[i] == 'r') ++c;
  }
  return c;
}
pair<long long int, long long int> dfs(int node, long long int rc,
                                       long long int lt) {
  for (int i = 0; i < adj[node].size(); ++i) {
    pair<long long int, long long int> p = ans[adj[node][i]];
    if (ans[node].first < p.first) {
      ans[adj[node][i]].first = ans[node].first;
      ans[adj[node][i]].second = ans[node].second;
      dfs(adj[node][i], p.first, p.second);
    } else if (ans[node].first == p.first && ans[node].second < p.second) {
      ans[adj[node][i]].second = ans[node].second;
      dfs(adj[node][i], p.first, p.second);
    }
  }
  return make_pair(ans[node].first, ans[node].second);
}
map<string, pair<int, pair<long long int, long long int> > > mp;
map<int, string> mp2;
int main() {
  int i, j, k = 1;
  cin >> m;
  for (i = 0; i < m; ++i) {
    cin >> s[i];
    s[i] = convert(s[i]);
    long long int rc = countr(s[i]);
    if (mp.find(s[i]) == mp.end()) {
      mp[s[i]] = make_pair(k, make_pair(rc, s[i].length()));
      ans[k] = make_pair(rc, s[i].length());
      mp2[k] = s[i];
      ++k;
    }
  }
  int words = k;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> s1[i][0] >> s1[i][1];
    s1[i][0] = convert(s1[i][0]);
    s1[i][1] = convert(s1[i][1]);
    if (mp.find(s1[i][0]) == mp.end()) {
      int rc = countr(s1[i][0]);
      mp[s1[i][0]] = make_pair(k, make_pair(rc, s1[i][0].length()));
      ans[k] = make_pair(rc, s1[i][0].length());
      mp2[k] = s1[i][0];
      ++k;
    }
    if (mp.find(s1[i][1]) == mp.end()) {
      long long int rc = countr(s1[i][1]);
      mp[s1[i][1]] = make_pair(k, make_pair(rc, s1[i][1].length()));
      ans[k] = make_pair(rc, s1[i][1].length());
      mp2[k] = s1[i][1];
      ++k;
    }
    adj[mp[s1[i][1]].first].push_back(mp[s1[i][0]].first);
  }
  for (i = 1; i < k; ++i) {
    dfs(i, ans[i].first, ans[i].second);
  }
  long long int p_min = 0, l_min = 0;
  for (i = 1; i <= m; ++i) {
    p_min += ans[mp[s[i - 1]].first].first;
    l_min += ans[mp[s[i - 1]].first].second;
  }
  cout << p_min << " " << l_min << "\n";
  return 0;
}
