#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const long long INF = 1000 * 1000 * 1000;
string to_lower(string x) {
  for (int i = 0; i < x.length(); i++)
    if (x[i] >= 'A' && x[i] <= 'Z') x[i] = 'a' + x[i] - 'A';
  return x;
}
int cnt_r(string x) {
  int res = 0;
  for (int i = 0; i < x.length(); i++) res += x[i] == 'r' ? 1 : 0;
  return res;
}
bool cmp(const string& a, const string& b) {
  int ra = cnt_r(a);
  int rb = cnt_r(b);
  if (ra != rb) return ra < rb;
  return a.length() < b.length();
}
map<string, std::vector<string> > graph;
map<string, pair<long long, long long> > dp;
map<string, bool> used;
void dfs(string& x, pair<long long, long long> variant) {
  used[x] = true;
  std::vector<string>& v = graph[x];
  for (int i = 0; i < v.size(); i++) {
    string& to = v[i];
    if (!used[to]) {
      dp[to] = variant;
      dfs(to, variant);
    }
  }
}
int main() {
  int m, n;
  string s;
  std::vector<string> text;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s;
    text.push_back(to_lower(s));
  }
  std::vector<string> all;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    s1 = to_lower(s1);
    s2 = to_lower(s2);
    graph[s2].push_back(s1);
    all.push_back(s2);
  }
  sort(all.begin(), all.end(), cmp);
  for (int i = 0; i < all.size(); i++) {
    string& cur = all[i];
    long long rs = cnt_r(cur);
    long long len = cur.length();
    if (!used[cur]) dfs(cur, pair<long long, long long>(rs, len));
    ;
  }
  long long rs = 0;
  long long len = 0;
  for (int i = 0; i < text.size(); i++) {
    string& cur = text[i];
    pair<long long, long long> best = pair<long long, long long>(INF, INF);
    if (dp.count(cur) != 0) best = dp[cur];
    pair<long long, long long> cur_v =
        pair<long long, long long>(cnt_r(cur), cur.length());
    if (best > cur_v) best = cur_v;
    rs += best.first;
    len += best.second;
  }
  cout << rs << ' ' << len << endl;
  return 0;
}
