#include <bits/stdc++.h>
using namespace std;
int m, n;
map<string, int> pt;
int ori[1000005], oril[1000005];
int essayid[1000005], id;
vector<int> adj[1000005], radj[1000005];
vector<pair<pair<int, int>, int> > evt;
pair<int, int> aa[1000005];
void low(string &s) {
  for (char &x : s) {
    if (x >= 'A' && x <= 'Z') x -= 'A', x += 'a';
  }
}
int getR(string &s) {
  int res = 0;
  for (char x : s)
    if (x == 'r') res++;
  return res;
}
int q[1000005];
void isi(int x, pair<int, int> aaa) {
  if (aa[x].first != -1) return;
  aa[x] = aaa;
  q[0] = x;
  for (int qh = 0, qt = 1; qh < qt; qh++) {
    int cur = q[qh];
    for (int v : radj[cur])
      if (aa[v].first == -1) {
        aa[v] = aaa;
        q[qt++] = v;
      }
  }
}
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first != b.first.first) return a.first.first < b.first.first;
  return a.first.second < b.first.second;
}
int main() {
  for (int i = 0; i < 1000005; i++) aa[i] = {-1, -1};
  cin >> m;
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    low(s);
    ori[i] = getR(s);
    oril[i] = s.length();
    if (pt.find(s) != pt.end())
      essayid[i] = pt[s];
    else {
      pt[s] = id;
      essayid[i] = id++;
      evt.push_back({{getR(s), s.length()}, id - 1});
    }
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    low(a), low(b);
    int ia, ib;
    if (pt.find(a) != pt.end()) {
      ia = pt[a];
    } else {
      evt.push_back({{getR(a), a.length()}, id});
      pt[a] = id;
      ia = id++;
    }
    if (pt.find(b) != pt.end()) {
      ib = pt[b];
    } else {
      evt.push_back({{getR(b), b.length()}, id});
      pt[b] = id;
      ib = id++;
    }
    adj[ia].push_back(ib);
    radj[ib].push_back(ia);
  }
  sort(evt.begin(), evt.end(), cmp);
  for (auto i : evt) {
    isi(i.second, i.first);
  }
  pair<long long, long long> ans;
  for (int i = 0; i < m; i++) {
    int cur = essayid[i];
    if (aa[cur].first == -1) {
      assert(0);
    } else {
      ans.first += (long long)aa[cur].first,
          ans.second += (long long)aa[cur].second;
    }
  }
  printf("%lld %lld\n", ans.first, ans.second);
  return 0;
}
