#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
map<string, int> bia;
map<int, string> fan;
vector<string> vec;
vector<int> lin[N];
int vt[N];
string S, T;
long long arr[N], cnt[N], c, r, l, n, m, best[N];
void lower(string &q) {
  for (int i = 0; i < q.size(); i++)
    if (q[i] >= 'A' && q[i] <= 'Z') q[i] += 'a' - 'A';
}
int coun(string q) {
  int res = 0;
  for (int i = 0; i < q.size(); i++) res += (q[i] == 'r');
  return res;
}
void add(string q) {
  if (bia.find(q) != bia.end()) return;
  bia[q] = c;
  fan[c] = q;
  cnt[c++] = coun(q);
}
bool cmp(string a, string b) {
  if (cnt[bia[a]] == cnt[bia[b]]) return a.size() < b.size();
  return cnt[bia[a]] < cnt[bia[b]];
}
void dfs(int a, int col) {
  vt[a] = 1;
  best[a] = col;
  for (int i = 0; i < lin[a].size(); i++)
    if (!vt[lin[a][i]]) dfs(lin[a][i], col);
}
int main() {
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> S;
    lower(S);
    add(S);
    arr[i] = bia[S];
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S >> T;
    lower(S), lower(T);
    add(S), add(T);
    lin[bia[T]].push_back(bia[S]);
  }
  map<string, int>::iterator it;
  for (it = bia.begin(); it != bia.end(); it++) vec.push_back(it->first);
  sort(vec.begin(), vec.end(), cmp);
  for (int i = 0; i < vec.size(); i++)
    if (!vt[bia[vec[i]]]) dfs(bia[vec[i]], bia[vec[i]]);
  for (int i = 0; i < m; i++) {
    r += cnt[best[arr[i]]];
    l += fan[best[arr[i]]].size();
  }
  cout << r << " " << l << endl;
  return 0;
}
