#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    map<string, int> ids;
    vector<pair<int, int>> cost;
    vector<vector<int>> rev;
    auto get = [&](string s) {
        for (char &c : s)
            c = tolower((unsigned char)c);
        auto it = ids.find(s);
        if (it != ids.end())
            return it->second;
        int id = ids.size();
        ids[s] = id;
        cost.push_back({count(s.begin(), s.end(), 'r'), s.size()});
        rev.emplace_back();
        return id;
    };
    int m;
    cin >> m;
    vector<int> essay(m);
    for (int &id : essay) {
        string s;
        cin >> s;
        id = get(s);
    }
    int e;
    cin >> e;
    while (e--) {
        string a, b;
        cin >> a >> b;
        int u = get(a), v = get(b);
        rev[v].push_back(u);
    }
    int n = ids.size();
    vector<int> order(n);
    iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&](int a, int b) { return cost[a] < cost[b]; });
    vector<bool> seen(n);
    vector<pair<int, int>> best(n);
    for (int source : order)
        if (!seen[source]) {
            vector<int> st{source};
            seen[source] = true;
            while (!st.empty()) {
                int v = st.back();
                st.pop_back();
                best[v] = cost[source];
                for (int u : rev[v])
                    if (!seen[u])
                        seen[u] = true, st.push_back(u);
            }
        }
    ll r = 0, len = 0;
    for (int v : essay) {
        r += best[v].first;
        len += best[v].second;
    }
    cout << r << ' ' << len << '\n';
}
