#include <bits/stdc++.h>
using namespace std;
stringstream ss;
long long mod = 1000000007LL;
struct T {
  pair<long long, long long> hash;
  int r, len;
  T(pair<long long, long long> hash = pair<long long, long long>(0, 0),
    int r = 0, int len = 0)
      : hash(hash), r(r), len(len) {}
  bool operator<(const T &other) const {
    if (r == other.r) {
      if (len == other.len) return hash > other.hash;
      return len > other.len;
    }
    return r > other.r;
  }
};
vector<int> adj[200010];
map<pair<long long, long long>, int> mp;
T s[100010], all[200010];
priority_queue<T> pq;
pair<int, int> dp[200010];
int p[200010];
T make(string s) {
  T ret;
  ret.r = count(s.begin(), s.end(), 'r');
  ret.len = s.size();
  for (int i = 0; i < ret.len; i++) {
    ret.hash.first = ret.hash.first * 127LL + s[i];
    ret.hash.second = ret.hash.second * mod + s[i];
  }
  return ret;
}
string f(string s) {
  for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);
  return s;
}
int cmp(int x, int y) {
  if (all[x].r != all[y].r) return all[x].r < all[y].r;
  return all[x].len < all[y].len;
}
int main() {
  int m, n;
  string t, tt;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> t;
    s[i] = make(f(t));
  }
  cin >> n;
  mp.clear();
  int id = 0;
  for (int i = 0; i < n; i++) {
    cin >> t >> tt;
    T x = make(f(t)), y = make(f(tt));
    if (!mp.count(x.hash)) {
      mp[x.hash] = ++id;
      all[id] = x;
    }
    if (!mp.count(y.hash)) {
      mp[y.hash] = ++id;
      all[id] = y;
    }
    adj[mp[y.hash]].push_back(mp[x.hash]);
  }
  for (int i = 1; i <= id; i++) dp[i].first = dp[i].second = mod;
  for (int i = 1; i <= id; i++) p[i] = i;
  sort(p + 1, p + 1 + id, cmp);
  for (int i = 1; i <= id; i++)
    if (dp[p[i]].first == mod) {
      int x = p[i];
      dp[x] = pair<int, int>(all[x].r, all[x].len);
      pq.push(all[x]);
      while (!pq.empty()) {
        pair<int, int> r(pq.top().r, pq.top().len);
        int id = mp[pq.top().hash];
        pq.pop();
        for (int i = 0; i < adj[id].size(); i++) {
          int y = adj[id][i];
          if (dp[y] > dp[id]) {
            dp[y] = dp[id];
            pq.push(all[y]);
          }
        }
      }
    }
  pair<long long, long long> ans(0, 0), r;
  for (int i = 0; i < m; i++) {
    if (mp.count(s[i].hash)) {
      id = mp[s[i].hash];
      r = dp[id];
    } else
      r = pair<int, int>(s[i].r, s[i].len);
    ans.first += r.first;
    ans.second += r.second;
  }
  cout << ans.first << " " << ans.second << endl;
  return 0;
}
