#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 7;
class Compare {
 public:
  bool operator()(const string &s, const string &t) const {
    if (s.size() != t.size()) return (s.size() < t.size());
    for (int i = 0, _n = (s.size()); i < _n; i = i + 1) {
      if (s[i] < t[i]) return (true);
      if (s[i] > t[i]) return (false);
    }
    return (false);
  }
};
map<string, int, Compare> wid;
pair<int, int> val[300300], vcp[300300], f[300300];
vector<int> g[300300], h[300300];
int low[300300], num[300300], cpid[300300];
vector<int> tid;
bool fre[300300];
int nw, nc, cnt;
stack<int> st;
template <class T>
inline void minimize(T &x, const T &y) {
  if (x > y) x = y;
}
inline int nextint(void) {
  int x;
  cin >> x;
  return (x);
}
inline string nextstring(void) {
  string s;
  cin >> s;
  for (__typeof((s).begin()) it = (s).begin(); it != (s).end(); it++)
    if ('a' <= *it && *it <= 'z') *it -= 'a' - 'A';
  return (s);
}
inline pair<int, int> value(const string &s) {
  int res = 0;
  for (__typeof((s).begin()) it = (s).begin(); it != (s).end(); it++)
    if (*it == 'R') res++;
  return (pair<int, int>(res, s.size()));
}
inline int strid(const string &s) {
  __typeof(wid.begin()) it = wid.find(s);
  if (it == wid.end()) {
    wid[s] = ++nw;
    val[nw] = value(s);
    return (nw);
  }
  return (it->second);
}
void init(void) {
  for (int zz = 0, _n = (nextint()); zz < _n; zz = zz + 1)
    tid.push_back(strid(nextstring()));
  for (int zz = 0, _n = (nextint()); zz < _n; zz = zz + 1) {
    int u = strid(nextstring());
    int v = strid(nextstring());
    g[u].push_back(v);
  }
  for (int i = (1), _b = (nw); i <= _b; i = i + 1) fre[i] = true;
}
void visit(int u) {
  low[u] = num[u] = ++cnt;
  st.push(u);
  for (__typeof((g[u]).begin()) it = (g[u]).begin(); it != (g[u]).end(); it++)
    if (fre[*it]) {
      int v = *it;
      if (num[v] == 0) {
        visit(v);
        minimize(low[u], low[v]);
      } else
        minimize(low[u], num[v]);
    }
  if (low[u] == num[u]) {
    int v;
    nc++;
    do {
      v = st.top();
      st.pop();
      cpid[v] = nc;
      fre[v] = false;
    } while (v != u);
  }
}
void tarjan(void) {
  for (int i = (1), _b = (nw); i <= _b; i = i + 1)
    if (num[i] == 0) visit(i);
  for (int i = (1), _b = (nc); i <= _b; i = i + 1)
    vcp[i] = pair<int, int>(INF, INF);
  for (int i = (1), _b = (nw); i <= _b; i = i + 1)
    minimize(vcp[cpid[i]], val[i]);
  for (int i = (1), _b = (nc); i <= _b; i = i + 1)
    f[i] = pair<int, int>(-1, -1);
  for (int i = (1), _b = (nw); i <= _b; i = i + 1)
    for (__typeof((g[i]).begin()) it = (g[i]).begin(); it != (g[i]).end();
         it++) {
      int j = *it;
      if (cpid[i] != cpid[j]) h[cpid[i]].push_back(cpid[j]);
    }
}
pair<int, int> dp(int u) {
  if (f[u].first >= 0) return (f[u]);
  f[u] = vcp[u];
  for (__typeof((h[u]).begin()) it = (h[u]).begin(); it != (h[u]).end(); it++)
    minimize(f[u], dp(*it));
  return (f[u]);
}
void process(void) {
  long long cnt = 0;
  long long len = 0;
  for (__typeof((tid).begin()) it = (tid).begin(); it != (tid).end(); it++) {
    pair<int, int> tmp = dp(cpid[*it]);
    cnt += tmp.first;
    len += tmp.second;
  }
  cout << cnt << " " << len;
}
int main(void) {
  ios::sync_with_stdio(false);
  init();
  tarjan();
  process();
  return 0;
}
