#include <bits/stdc++.h>
using namespace std;
const int N = 800005;
const int K = 28;
struct vertex {
  int next[K];
  int id;
  vertex() {
    memset(next, -1, sizeof next);
    id = 0;
  }
} t[N];
int sz = 1;
int cnt = 0;
int cnt2 = 0;
int n, m;
int initial[N];
int color[N];
char s[N];
vector<int> g[N], g2[N], gr[N], order;
pair<int, int> value[N], value2[N];
bool used[N];
pair<long long, long long> ans;
bool calced[N];
void ToLower(int len) {
  for (int i = 0; i < len; ++i) s[i] = tolower(s[i]);
}
int add(int len) {
  int v = 1;
  for (int i = 0; i < len; ++i) {
    int to = s[i] - 'a';
    if (t[v].next[to] == -1) t[v].next[to] = ++sz;
    v = t[v].next[to];
  }
  if (!t[v].id) t[v].id = ++cnt;
  return t[v].id;
}
pair<int, int> calc(int len) {
  int r = 0;
  for (int i = 0; i < len; ++i) r += (s[i] == 'r' ? 1 : 0);
  return make_pair(r, len);
}
int in() {
  int len, index;
  scanf("%s", s);
  len = strlen(s);
  ToLower(len);
  index = add(len);
  value[index] = calc(len);
  return index;
}
void dfs1(int v) {
  used[v] = true;
  for (int i = 0; i < g[v].size(); ++i)
    if (!used[g[v][i]]) dfs1(g[v][i]);
  order.push_back(v);
}
void UpdPairs(pair<int, int> &a, pair<int, int> b) {
  if (a == make_pair(0, 0) || a > b) a = b;
}
void dfs2(int v, int CurColor) {
  color[v] = CurColor;
  UpdPairs(value2[CurColor], value[v]);
  for (int i = 0; i < gr[v].size(); ++i)
    if (!color[gr[v][i]]) dfs2(gr[v][i], CurColor);
}
void dfs3(int v) {
  used[v] = true;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (color[v] != color[to]) g2[color[v]].push_back(color[to]);
    if (!used[to]) dfs3(to);
  }
}
void CondensationOfGraph() {
  for (int i = 1; i <= cnt; ++i)
    if (!used[i]) dfs1(i);
  reverse(order.begin(), order.end());
  cnt2 = 0;
  for (int i = 0; i < order.size(); ++i) {
    int v = order[i];
    if (!color[v]) {
      ++cnt2;
      dfs2(v, cnt2);
    }
  }
  memset(used, false, sizeof used);
  for (int i = 1; i <= cnt; ++i)
    if (!used[i]) dfs3(i);
}
void AddPairs(pair<long long, long long> &a, pair<int, int> b) {
  a.first += b.first;
  a.second += b.second;
}
void Update(int v) {
  if (calced[v]) return;
  for (int i = 0; i < g2[v].size(); ++i) {
    int to = g2[v][i];
    Update(to);
    UpdPairs(value2[v], value2[to]);
  }
  calced[v] = true;
}
int main() {
  scanf("%d\n", &n);
  for (int i = 1; i <= n; ++i) initial[i] = in();
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int FromId = in();
    int ToId = in();
    if (FromId != ToId) {
      g[FromId].push_back(ToId);
      gr[ToId].push_back(FromId);
    }
  }
  CondensationOfGraph();
  for (int i = 1; i <= n; ++i) {
    int id = initial[i];
    if (!calced[color[id]]) Update(color[id]);
    AddPairs(ans, value2[color[id]]);
  }
  printf("%I64d %I64d\n", ans.first, ans.second);
  return 0;
}
