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

using ll = long long;
using Pi = pair < ll , ll >;

const ll INF = (1LL << 40) - 1;

ll dp[1000005], dp2[1000005];
int main()
{
        int N;
        while ( cin >> N, N ) {
                ll hp[105];
                Pi all[105], single[105];

                int M;
                int mall, msin;
                vector < Pi > list1, list2;

                mall = msin = 0;

                for ( int i = 0; i < N; i++ ) {
                        cin >> hp[i];
                }
                sort(hp, hp + N);

                cin >> M;       
                while ( M-- ) {
                        string name, type;
                        int mp, damage;

                        cin >> name >> mp >> type >> damage;
                        if ( type == "Single" ) {
                                single[msin++] = Pi(mp, damage);
                        } else {
                                all[mall++] = Pi(mp, damage);
                        }
                }

                fill_n(dp, 100005, -INF);
                dp[0] = 0;
                for ( int i = 0; i <= 100000; i++ ) {
                        if ( dp[i] == -INF ) continue;
                        for ( int j = 0; j < mall; j++ ) {
                                int pos = i + all[j].first;
                                if ( pos > 100000 ) continue;
                                if ( all[j].first == 0 && all[j].second > 0 ) {
                                        dp[i] = 1000000000;
                                }
                                dp[pos] = max(dp[pos], dp[i] + all[j].second);
                        }
                        list1.emplace_back(i, dp[i]);
                }

                fill_n(dp2, 100005, -INF);
                dp2[0] = 0;
                for ( int i = 0; i <= 100000; i++ ) {
                        if ( dp2[i] == -INF ) continue;
                        for ( int j = 0; j < msin; j++ ) {
                                int pos = i + single[j].first;
                                if ( pos > 100000 ) continue;
                                if ( single[j].first == 0 && single[j].second > 0 ) {
                                        dp2[i] = 1000000000;
                                }
                                dp2[pos] = max(dp2[pos], dp2[i] + single[j].second);
                        }
                        if ( dp2[i] > 0 ) list2.emplace_back(dp2[i], i);
                }
                sort(begin(list2), end(list2));
                
                ll minv = INF;
                for ( int i = list2.size() - 1; i >= 0; i-- ) {
                        minv = min(list2[i].second, minv);
                        list2[i].second = minv;
                }

                minv = INF;     
                for ( auto &gdamage : list1 ) {
                        ll mp = gdamage.first;
                        ll damage = gdamage.second;
                        for ( int i = 0; i < N; i++ ) {
                                if ( hp[i] <= damage ) continue;
                                auto p = lower_bound(begin(list2), end(list2), Pi(hp[i] - damage, 0));
                                if ( p == end(list2) ) mp = INF;
                                else mp += p->second;
                        }
                        minv = min(minv, mp);
                }
                cout << minv << endl;
        }
        return ( 0 );
}



Measured memory_bytes: 9632