#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    while (cin >> N, N)
    {

        vector<ll> HP(N);
        for (int i = 0; i < N; i++)
        {
            cin >> HP[i];
        }
        int M;
        cin >> M;
        vector<P> single, all;
        for (int i = 0; i < M; i++)
        {
            string name, target;
            int mp, damage;
            cin >> name >> mp >> target >> damage;
            if (target == "All")
                all.push_back(P(mp, damage));
            else
                single.push_back(P(mp, damage));
        }
        // dp1[i] := All で i ダメージ与える最小コスト
        // dp2[i] := Single で i ダメージ与える最小コスト
        vector<ll> dp1(111111, INF), dp2(111111, INF);
        dp1[0] = 0;
        dp2[0] = 0;
        for (int i = 0; i < (int)all.size(); i++)
        {
            int mp = all[i].first, d = all[i].second;
            for (int j = 0; j <= 100000; j++)
            {
                if (j + d > 100000)
                {
                    dp1[100001] = min(dp1[100001], dp1[j] + mp);
                }
                else
                {
                    dp1[j + d] = min(dp1[j + d], dp1[j] + mp);
                }
            }
        }
        for (int i = 0; i < (int)single.size(); i++)
        {
            int mp = single[i].first, d = single[i].second;
            for (int j = 0; j <= 100000; j++)
            {
                if (j + d > 100000)
                {
                    dp2[100001] = min(dp2[100001], dp2[j] + mp);
                }
                else
                {
                    dp2[j + d] = min(dp2[j + d], dp2[j] + mp);
                }
            }
        }
        for (int i = 100000; i >= 0; i--)
        {
            dp1[i] = min(dp1[i], dp1[i + 1]);
            dp2[i] = min(dp2[i], dp2[i + 1]);
            // assert(dp1[i] != INF);
            // assert(dp2[i] != INF);
        }
        ll res = INF;
        for (int i = 0; i <= 100000; i++)
        {
            ll tmp = dp1[i];
            for (int j = 0; j < N; j++)
            {
                if (HP[j] <= i)
                    continue;
                tmp += dp2[HP[j] - i];
            }
            res = min(res, tmp);
        }
        cout << res << endl;
    }
}

