#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct POINT {
  T x, y;
  POINT() {}
  POINT(T _x, T _y) : x(_x), y(_y) {}
  inline bool operator<(const POINT<T> &p) {
    return (x < p.x) || (x == p.x && y < p.y);
  }
};
template <typename T>
inline istream &operator>>(istream &is, POINT<T> &p) {
  is >> p.x >> p.y;
  return is;
}
template <typename T>
inline ostream &operator<<(ostream &os, POINT<T> &p) {
  os << p.x << ' ' << p.y;
  return os;
}
template <typename T>
struct VECTOR {
  T x, y;
  VECTOR() {}
  VECTOR(T _x, T _y) : x(_x), y(_y) {}
  inline const VECTOR<T> operator-() const { return VECTOR<T>(-x, -y); }
  inline operator POINT<T>() const { return POINT<T>(x, y); }
};
template <typename T>
inline const VECTOR<T> operator+(const VECTOR<T> &v, const VECTOR<T> &u) {
  return VECTOR<T>(v.x + u.x, v.y + u.y);
}
template <typename T>
inline const VECTOR<T> operator-(const VECTOR<T> &v, const VECTOR<T> &u) {
  return VECTOR<T>(v.x - u.x, v.y - u.y);
}
template <typename T>
inline const VECTOR<T> operator*(const VECTOR<T> &v, T a) {
  return VECTOR<T>(v.x * a, v.y * a);
}
template <typename T>
inline const VECTOR<T> operator/(const VECTOR<T> &v, T a) {
  return VECTOR<T>(v.x / a, v.y / a);
}
template <typename T>
inline const VECTOR<T> operator*(T a, const VECTOR<T> &v) {
  return VECTOR<T>(v.x * a, v.y * a);
}
template <typename T>
inline const VECTOR<T> operator/(T a, const VECTOR<T> &v) {
  return VECTOR<T>(v.x / a, v.y / a);
}
template <typename T>
inline const POINT<T> operator+(const POINT<T> &p, const VECTOR<T> &v) {
  return p + (POINT<T>)v;
}
template <typename T>
inline const POINT<T> operator-(const POINT<T> &p, const VECTOR<T> &v) {
  return p - (POINT<T>)v;
}
template <typename T>
inline istream &operator>>(istream &is, VECTOR<T> &v) {
  is >> v.x >> v.y;
  return is;
}
template <typename T>
inline ostream &operator<<(ostream &os, VECTOR<T> &v) {
  os << v.x << ' ' << v.y;
  return os;
}
const long double PI = acos(-1.0);
const long double EPS = 1E-9;
const int MAXN = 100000 + 228;
const int INF = INT_MAX - 228;
const long long LLINF = LLONG_MAX - 228;
template <typename T>
inline const VECTOR<T> GET_VEC(POINT<T> a, POINT<T> b) {
  return VECTOR<T>(b.x - a.x, b.y - a.y);
}
template <typename T>
inline T SCAL_PR(const VECTOR<T> &v, const VECTOR<T> &u) {
  return v.x * u.x + v.y * u.y;
}
template <typename T>
inline T VEC_PR(const VECTOR<T> &v, const VECTOR<T> &u) {
  return v.x * u.y - v.y * u.x;
}
template <typename T>
inline long double LEN(const VECTOR<T> &v) {
  return sqrt(SCAL_PR(v, v));
}
int m;
vector<tuple<int, int, int> > text;
unordered_map<string, int> num;
vector<tuple<int, int, int> > q;
int n;
string x, y;
unordered_map<int, vector<int> > syn;
unordered_map<int, pair<int, int> > best;
int cnt_r, len, word;
long long rans, lans;
int hy, hx;
void UP(string &str) {
  for (int i = 0; i < (int)str.size(); ++i) str[i] = toupper(str[i]);
}
int R_CNT(string &str) {
  int ans = 0;
  for (int i = 0; i < (int)str.size(); ++i)
    if (str[i] == 'R') ++ans;
  return ans;
}
int H(string str) {
  int h = 0, p = 1000000000 + 13, q = 228;
  for (int i = 0; i < (int)str.size(); ++i)
    h = (h + (str[i] - 'A' + 1) * q) * q % p;
  return h;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> x;
    UP(x), hx = H(x);
    text.push_back(make_tuple(R_CNT(x), (int)x.size(), hx));
  }
  q = text;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x >> y;
    UP(x), hx = H(x);
    UP(y), hy = H(y);
    syn[hy].push_back(hx);
    q.push_back(make_tuple(R_CNT(y), (int)y.size(), hy));
  }
  sort(q.begin(), q.end());
  reverse(q.begin(), q.end());
  while (!q.empty()) {
    cnt_r = get<0>(q.back());
    len = get<1>(q.back());
    word = get<2>(q.back());
    q.pop_back();
    if (best.find(word) == best.end()) {
      best[word] = make_pair(cnt_r, len);
      for (int j = 0; j < (int)syn[word].size(); ++j)
        if (best.find(syn[word][j]) == best.end())
          q.push_back(make_tuple(cnt_r, len, syn[word][j]));
    }
  }
  for (int i = 0; i < m; ++i) {
    word = get<2>(text[i]);
    rans += best[word].first;
    lans += best[word].second;
  }
  cout << rans << ' ' << lans << '\n';
  return 0;
}
