#include <bits/stdc++.h>
using namespace std;
const int N(1e5 + 20);
const int MAXN(4e5 + 200);
pair<int, int> db[MAXN];
struct hh {
  pair<int, int> x;
  int p;
  hh() {}
  hh(pair<int, int> _x, int _p) : x(_x), p(_p){};
  bool operator<(const hh &b) const { return x < b.x; }
} ddb[MAXN];
struct edge {
  int v, next;
} edges[MAXN];
int n, m, num, point[MAXN], pos[N];
map<string, int> mp;
bool in[MAXN], vis[N];
inline void change(string &x) {
  int len(x.length());
  for (int i(0); i < len; i++) {
    if (islower(x[i]))
      ;
    x[i] = toupper(x[i]);
  }
}
inline pair<int, int> get(string s) {
  int len(s.length()), n1(0);
  for (int i(0); i < len; i++)
    if (s[i] == 'R') n1++;
  return pair<int, int>(n1, len);
}
inline int get_hash(string s) {
  int res(0);
  if (!mp.count(s)) {
    res = mp[s] = ++num;
    db[num] = get(s);
    ddb[num] = hh(db[num], num);
  } else
    res = mp[s];
  return res;
}
inline void addedge(int u, int v) {
  static int en(0);
  edges[++en].next = point[u];
  point[u] = en;
  edges[en].v = v;
}
inline void spfa(int x) {
  static queue<int> q;
  q.push(x);
  in[x] = vis[x] = 1;
  while (!q.empty()) {
    int u(q.front());
    in[u] = 0;
    q.pop();
    for (int i(point[u]); i; i = edges[i].next) {
      int v(edges[i].v);
      if (db[u] < db[v]) db[v] = db[u], q.push(v), in[v] = vis[v] = 1;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  string s;
  for (int i(1); i <= n; i++) {
    cin >> s;
    change(s);
    pos[i] = get_hash(s);
  }
  cin >> m;
  for (int i(1); i <= m; i++) {
    cin >> s;
    change(s);
    int p(get_hash(s));
    cin >> s;
    change(s);
    int q(get_hash(s));
    addedge(q, p);
  }
  sort(ddb + 1, ddb + num + 1);
  for (int i(1); i <= num; i++)
    if (!vis[ddb[i].p]) spfa(ddb[i].p);
  long long ans1(0), ans2(0);
  for (int i(1); i <= n; i++)
    ans1 += db[pos[i]].first, ans2 += db[pos[i]].second;
  cout << ans1 << " " << ans2 << endl;
  return 0;
}
