#include <bits/stdc++.h>
using namespace std;
double PI = 3.141592653589793;
const double EPS = 1e-6;
const int N = 1e6 + 5;
const long long mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int n, m, idx[N], low[N], T;
vector<vector<int> > g, g2;
vector<int> S;
bool vis[N];
int compID[N], sz[N], cmp;
pair<long long, long long> val[N];
void DFS(int u) {
  idx[u] = low[u] = ++T;
  S.push_back(u);
  vis[u] = true;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    if (idx[v] == 0) DFS(v);
    if (vis[v]) low[u] = min(low[u], low[v]);
  }
  if (idx[u] == low[u]) {
    while (true) {
      int v = S.back();
      S.pop_back();
      vis[v] = false;
      compID[v] = cmp;
      sz[cmp]++;
      if (v == u) break;
    }
    ++cmp;
  }
}
string R(string& s) {
  string ret = "";
  for (int i = 0; i < s.size(); i++) ret += (char)tolower(s[i]);
  return ret;
}
long long calc(string& s) {
  long long ret = 0;
  for (int i = 0; i < s.size(); i++) ret += s[i] == 'r';
  return ret;
}
pair<long long, long long> dp[N];
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < g2[u].size(); i++) {
    if (!vis[g2[u][i]]) dfs(g2[u][i]);
    if (dp[g2[u][i]].first == dp[u].first &&
        dp[g2[u][i]].second < dp[u].second) {
      dp[u].second = dp[g2[u][i]].second;
    } else if (dp[g2[u][i]].first < dp[u].first) {
      dp[u].first = dp[g2[u][i]].first;
      dp[u].second = dp[g2[u][i]].second;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  g.resize(N);
  vector<int> v;
  map<string, int> mp;
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    s = R(s);
    if (!mp[s]) {
      mp[s] = cnt;
      val[cnt].first = calc(s);
      val[cnt].second = s.size();
      cnt++;
    }
    v.push_back(mp[s]);
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    string a, b;
    cin >> a >> b;
    a = R(a);
    b = R(b);
    if (!mp[a]) {
      mp[a] = cnt;
      val[cnt].first = calc(a);
      val[cnt].second = a.size();
      cnt++;
    }
    if (!mp[b]) {
      mp[b] = cnt;
      val[cnt].first = calc(b);
      val[cnt].second = b.size();
      cnt++;
    }
    g[mp[a]].push_back(mp[b]);
  }
  for (int i = 1; i <= cnt - 1; i++) {
    if (!idx[i]) DFS(i);
  }
  g2.resize(N);
  for (int i = 0; i <= cmp - 1; i++) {
    dp[i].first = 1e18;
    dp[i].second = 1e18;
  }
  for (int i = 1; i <= cnt - 1; i++) {
    if (val[i].first < dp[compID[i]].first) {
      dp[compID[i]].first = val[i].first;
      dp[compID[i]].second = val[i].second;
    } else if (val[i].first == dp[compID[i]].first &&
               val[i].second < dp[compID[i]].second) {
      dp[compID[i]].second = val[i].second;
    }
    for (int j = 0; j < g[i].size(); j++) {
      if (compID[i] != compID[g[i][j]])
        g2[compID[i]].push_back(compID[g[i][j]]);
    }
  }
  for (int i = 0; i <= cmp - 1; i++) {
    if (!vis[i]) dfs(i);
  }
  pair<long long, long long> ans = {0, 0};
  for (int i = 0; i <= n - 1; i++) {
    ans.first += dp[compID[v[i]]].first;
    ans.second += dp[compID[v[i]]].second;
  }
  cout << ans.first << " " << ans.second;
}
