#include <bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i,x) for(int i=0;i<x;++i)

const int inf = 1e9;

signed main()
{
    int N;

    while (cin >> N, N) {
        vector<int> hp(N);

        rep(i, N) {
            cin >> hp[i];
        }

        int M;

        cin >> M;

        vector<pair<int,int>> S, A;

        rep(i, M) {
            string s;
            int mp, dmg;
            cin >> s >> mp >> s >> dmg;
            if (s == "Single") S.push_back(make_pair(mp, dmg));
            else A.push_back(make_pair(mp, dmg));
        }

        vector<int> dp1(100010, inf), dp2(100010, inf);
        dp1[0] = dp2[0] = 0;

        for (int i = 0; i < S.size(); ++i) {
            int mp = S[i].first, dmg = S[i].second;
            for (int j = 0; j <= 100000; ++j) {
                if (j - dmg >= 0) {
                    dp1[j] = min(dp1[j], dp1[j - dmg] + mp);
                } else {
                    dp1[j] = min(dp1[j], mp);
                }
            }
        }

        for (int i = 0; i < A.size(); ++i) {
            int mp = A[i].first, dmg = A[i].second;
            for (int j = 0; j <= 100000; ++j) {
                if (j - dmg >= 0) {
                    dp2[j] = min(dp2[j], dp2[j - dmg] + mp);
                } else {
                    dp2[j] = min(dp2[j], mp);
                }
            }
        }

        int mi = inf;

        for (int a = 0; a <= 100000; ++a) {
            int sum = dp2[a];

            for (int i = 0; i < N; ++i) {
                if (hp[i] - a >= 0) {
                    sum += dp1[hp[i] - a];
                }
            }

            mi = min(mi, sum);
        }

        cout << mi << endl;
    }
}