#include <bits/stdc++.h>
using namespace std;
string norm(string t) {
  for (int i = 0; i < (int)(t.size()); ++i) {
    if (t[i] >= 'a' && t[i] <= 'z') t[i] += 'A' - 'a';
  }
  return t;
}
map<string, pair<int, int> > dp;
map<string, vector<string> > edges;
void dfs(const string &t, pair<int, int> s) {
  if (dp.count(t)) return;
  dp[t] = s;
  if (edges.count(t))
    for (auto x : edges[t]) dfs(x, s);
}
int rcount(const string &s) {
  int c = 0;
  for (int i = 0; i < (int)(s.size()); ++i)
    if (s[i] == 'R') ++c;
  return c;
}
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < (int)(N); ++i) {
    cin >> s[i];
    s[i] = norm(s[i]);
  }
  int M;
  cin >> M;
  vector<pair<pair<int, int>, string> > f;
  for (int i = 0; i < (int)(M); ++i) {
    string u, v;
    cin >> u >> v;
    v = norm(v);
    u = norm(u);
    edges[v].push_back(u);
    f.push_back(make_pair(make_pair(rcount(v), v.size()), v));
  }
  sort((f).begin(), (f).end());
  for (auto x : f) {
    dfs(x.second, x.first);
  }
  long long a = 0, b = 0;
  for (int i = 0; i < (int)(N); ++i) {
    pair<int, int> l =
        dp.count(s[i]) ? dp[s[i]] : make_pair(rcount(s[i]), (int)s[i].size());
    l = min(l, make_pair(rcount(s[i]), (int)s[i].size()));
    a += l.first;
    b += l.second;
  }
  cout << a << ' ' << b << '\n';
  return 0;
}
