#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > v;
map<string, long long> M1;
map<long long, pair<long long, long long> > M2;
vector<long long> seen;
vector<pair<long long, long long> > check;
long long maxi, ret, maxl;
void dfs(long long ind, pair<long long, long long> b) {
  check[ind] = min(b, check[ind]);
  if (seen[ind]) {
    return;
  }
  seen[ind] = 1;
  long long i;
  for (i = 0; i < v[ind].size(); i++) {
    dfs(v[ind][i], check[ind]);
  }
}
int main() {
  long long m;
  long long i, j;
  set<string> s;
  cin >> m;
  vector<string> start;
  for (i = 0; i < m; i++) {
    string str;
    cin >> str;
    for (j = 0; j < str.length(); j++) {
      if (str[j] >= 'A' && str[j] <= 'Z') {
        str[j] = 'a' + str[j] - 'A';
      }
    }
    start.push_back(str);
  }
  long long n;
  std::vector<pair<pair<long long, long long>, long long> > adj;
  cin >> n;
  long long ind = 0;
  for (i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    pair<long long, long long> p1, p2;
    p1.first = p2.first = 0;
    for (j = 0; j < s1.length(); j++) {
      if (s1[j] >= 'A' && s1[j] <= 'Z') {
        s1[j] = 'a' + s1[j] - 'A';
      }
      if (s1[j] == 'r') {
        p1.first++;
      }
    }
    for (j = 0; j < s2.length(); j++) {
      if (s2[j] >= 'A' && s2[j] <= 'Z') {
        s2[j] = 'a' + s2[j] - 'A';
      }
      if (s2[j] == 'r') {
        p2.first++;
      }
    }
    p1.second = s1.length();
    p2.second = s2.length();
    long long x, y;
    if (s.find(s1) == s.end()) {
      s.insert(s1);
      M1[s1] = ind;
      M2[ind] = p1;
      vector<long long> ne;
      v.push_back(ne);
      x = ind;
      check.push_back(p1);
      seen.push_back(0);
      ind++;
    } else {
      x = M1[s1];
    }
    if (s.find(s2) == s.end()) {
      s.insert(s2);
      M1[s2] = ind;
      M2[ind] = p2;
      vector<long long> ne;
      v.push_back(ne);
      y = ind;
      check.push_back(p2);
      seen.push_back(0);
      ind++;
    } else {
      y = M1[s2];
    }
    v[y].push_back(x);
  }
  for (i = 0; i < ind; i++) {
    adj.push_back(make_pair(M2[i], i));
  }
  sort(adj.begin(), adj.end());
  for (i = 0; i < adj.size(); i++) {
    if (!seen[adj[i].second]) {
      dfs(adj[i].second, adj[i].first);
    }
  }
  long long r_count = 0, l = 0;
  for (i = 0; i < m; i++) {
    if (s.find(start[i]) == s.end()) {
      for (j = 0; j < start[i].length(); j++) {
        if (start[i][j] == 'r' || start[i][j] == 'R') {
          r_count++;
        }
      }
      l += start[i].length();
    } else {
      if (seen[M1[start[i]]]) {
        r_count += check[M1[start[i]]].first;
        l += check[M1[start[i]]].second;
      }
    }
  }
  cout << r_count << " " << l << endl;
  return 0;
}
