#include <bits/stdc++.h>
using namespace std;
map<string, string> mymap;
map<string, long long int> mymap1;
map<string, long long int> mymap2;
map<string, long long int> mymap3;
map<string, long long int> mymap4;
vector<string> v;
vector<string> v1[5000005];
vector<pair<string, long long int> > v2;
bool cmp(pair<string, long long int> p1, pair<string, long long int> p2) {
  if (p1.second < p2.second)
    return 1;
  else if (p1.second == p2.second) {
    long long int l1 = p1.first.size();
    long long int l2 = p2.first.size();
    return l1 < l2;
  } else
    return 0;
}
void dfs(string s, string s1) {
  for (int yu = 0; yu < v1[mymap1[s]].size(); yu++) {
    if (mymap2[v1[mymap1[s]][yu]] == 0) {
      mymap2[v1[mymap1[s]][yu]] = 1;
      if (mymap3[v1[mymap1[s]][yu]] > mymap3[s1])
        mymap[v1[mymap1[s]][yu]] = s1;
      else if (mymap3[v1[mymap1[s]][yu]] == mymap3[s1] &&
               s1.size() < v1[mymap1[s]][yu].size())
        mymap[v1[mymap1[s]][yu]] = s1;
      dfs(v1[mymap1[s]][yu], s1);
    }
  }
}
int main() {
  long long int i, j, k, l, n, m;
  string str, str1, str2;
  cin >> n;
  l = 0;
  for (i = 0; i < n; i++) {
    l = 0;
    cin >> str;
    k = str.size();
    for (j = 0; j < k; j++) {
      str[j] = tolower(str[j]);
      if (str[j] == 'r') l++;
    }
    if (mymap4[str] == 0) {
      v.push_back(str);
      mymap4[str] = 1;
    } else
      mymap4[str]++;
    mymap[str] = str;
    mymap3[str] = l;
  }
  cin >> m;
  long long int lu = 1, cnt = 0, k1, k2;
  for (i = 0; i < m; i++) {
    cnt = 0;
    cin >> str1 >> str2;
    k1 = str1.size();
    k2 = str2.size();
    for (j = 0; j < k1; j++) {
      str1[j] = tolower(str1[j]);
      if (str1[j] == 'r') cnt++;
    }
    mymap3[str1] = cnt;
    cnt = 0;
    for (j = 0; j < k2; j++) {
      str2[j] = tolower(str2[j]);
      if (str2[j] == 'r') cnt++;
    }
    mymap3[str2] = cnt;
    if (mymap1[str2] == 0) {
      mymap1[str2] = lu;
      lu++;
    }
    v1[mymap1[str2]].push_back(str1);
    v2.push_back(make_pair(str2, cnt));
  }
  sort(v2.begin(), v2.end(), cmp);
  k = v2.size();
  for (i = 0; i < k; i++) {
    if (mymap2[v2[i].first] == 0) {
      mymap2[v2[i].first] = 1;
      dfs(v2[i].first, v2[i].first);
    }
  }
  long long int ans1 = 0, ans2 = 0;
  k = v.size();
  for (i = 0; i < k; i++) {
    ans1 += mymap3[mymap[v[i]]] * mymap4[v[i]];
    ans2 += mymap[v[i]].size() * mymap4[v[i]];
  }
  cout << ans1 << " " << ans2;
  return 0;
}
