#include <bits/stdc++.h>
using namespace std;
namespace twj {}
using namespace twj;
inline int getR(string second) {
  int res = 0;
  for (int i = 0; i < second.size(); ++i)
    res += (second[i] == 'R' || second[i] == 'r');
  return res;
}
int scccol[200005], col = 1;
vector<int> second;
bool ins[200005], use[200005];
int num[200005], tim, low[200005], N;
vector<int> v[200005];
pair<int, int> info[200005], dp[200005], best[200005];
inline void dfs(int x) {
  num[x] = ++tim;
  use[x] = 1;
  low[x] = num[x];
  ins[x] = 1;
  second.push_back(x);
  for (int i = 0; i < v[x].size(); ++i) {
    int y = v[x][i];
    if (!use[y]) {
      dfs(y);
      low[x] = min(low[x], low[y]);
    } else if (ins[y]) {
      low[x] = min(low[x], num[y]);
    }
  }
  if (num[x] == low[x]) {
    while (1) {
      int w = second.back();
      second.pop_back();
      scccol[w] = col;
      ins[w] = 0;
      if (info[w] < best[col]) best[col] = info[w];
      if (w == x) break;
    }
    ++col;
  }
  return;
}
vector<int> e[200005];
map<string, int> mpsi;
string str[200005];
inline pair<int, int> DP(int x) {
  if (dp[x].second) return dp[x];
  if (e[x].size() == 0) return dp[x] = best[x];
  dp[x] = best[x];
  for (int i = 0; i < e[x].size(); ++i) dp[x] = min(dp[x], DP(e[x][i]));
  return dp[x];
}
int n, m;
inline void toLower(string &second) {
  for (int i = 0; i < second.size(); ++i)
    if (isupper(second[i])) second[i] += 'a' - 'A';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  memset(best, 0x7f, sizeof(best));
  cin >> m;
  for (int i = 1; i <= m; ++i) cin >> str[i], toLower(str[i]);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    string x, y;
    cin >> x >> y;
    toLower(x);
    toLower(y);
    if (mpsi.find(x) == mpsi.end()) mpsi[x] = mpsi.size() + 1;
    if (mpsi.find(y) == mpsi.end()) mpsi[y] = mpsi.size() + 1;
    v[mpsi[x]].push_back(mpsi[y]);
    info[mpsi[x]] = make_pair(getR(x), x.size());
    info[mpsi[y]] = make_pair(getR(y), y.size());
  }
  N = mpsi.size();
  for (int i = 1; i <= N; ++i)
    if (!use[i]) dfs(i);
  for (int i = 1; i <= N; ++i)
    for (int j = 0; j < v[i].size(); ++j)
      e[scccol[i]].push_back(scccol[v[i][j]]);
  pair<long long, long long> ans = make_pair(0, 0);
  for (int i = 1; i <= m; ++i) {
    string t = str[i];
    if (mpsi.find(t) == mpsi.end())
      ans.first += getR(t), ans.second += t.size();
    else {
      int id = scccol[mpsi[t]];
      pair<int, int> tt = DP(id);
      ans.first += tt.first;
      ans.second += tt.second;
    }
  }
  cout << ans.first << " " << ans.second;
  return 0;
}
