#include <bits/stdc++.h>
using namespace std;
long long int n, m, an1, an2, vis[300010], k;
vector<int> adj[300010];
map<string, int> mp;
string s[100010], s1, s2, ar[300010];
string tol(string s) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] >= 'A' && s[i] <= 'Z') {
      s[i] += 'a' - 'A';
    }
  }
  return s;
}
struct p {
  long long int leng, rval, in;
} ans[300010], a2[300010];
void dfs(int n, struct p x) {
  if (vis[n]) return;
  vis[n] = 1;
  ans[n] = x;
  for (int i = 0; i < adj[n].size(); i++) {
    dfs(adj[n][i], x);
  }
  return;
}
bool cmp(struct p r, struct p l) {
  if (r.rval == l.rval)
    return (l.leng > r.leng);
  else
    return (l.rval > r.rval);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    s[i] = tol(s[i]);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s1 >> s2;
    s1 = tol(s1);
    s2 = tol(s2);
    if (mp.find(s1) == mp.end()) {
      mp[s1] = k;
      ar[k] = s1;
      k++;
    }
    if (mp.find(s2) == mp.end()) {
      mp[s2] = k;
      ar[k] = s2;
      k++;
    }
    adj[mp[s2]].push_back(mp[s1]);
  }
  for (int i = 0; i < k; i++) {
    a2[i].rval = 0;
    for (int j = 0; j < ar[i].size(); j++)
      if (ar[i][j] == 'r') a2[i].rval++;
    a2[i].leng = ar[i].size();
    a2[i].in = i;
    ans[i] = a2[i];
  }
  sort(a2, a2 + k, cmp);
  for (int i = 0; i < k; i++) {
    if (!vis[a2[i].in]) {
      dfs(a2[i].in, a2[i]);
    }
  }
  for (int i = 0; i < n; i++) {
    if (mp.find(s[i]) == mp.end()) {
      for (int j = 0; j < s[i].size(); j++) {
        if (s[i][j] == 'r') an1++;
      }
      an2 += s[i].size();
    } else {
      an1 += ans[mp[s[i]]].rval;
      an2 += ans[mp[s[i]]].leng;
    }
  }
  cout << an1 << " " << an2 << endl;
}
