#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e14;

int n, m;
vector<int> h;
vector<P> m1, m2; 
int dp[100010], dp2[100010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(cin >> n, n){
        h.resize(n);
        m1.clear();
        m2.clear();
        rep(i, 0, n){
            cin >> h[i];
        }
        cin >> m;
        rep(i, 0, m){
            string s1;
            int mp, damage;
            cin >> s1 >> mp >> s1 >> damage;
            if(s1 == "Single"){
                m1.push_back(P(mp, damage));
            }else if(s1 == "All"){  
                m2.push_back(P(mp, damage));
            }
        }
        rep(i, 0, 100010){
            dp[i] = dp2[i] = INF;
        }
        dp[0] = dp2[0] = 0;
        rep(i, 0, m1.size()){
            rep(j, 0, 100001){
                if(dp[j] == INF) continue;
                int next = j + m1[i].second;
                if(next > 100000) next = 100001;
                chmin(dp[next], dp[j] + m1[i].first);
            }
        }
        rep(i, 0, m2.size()){
            rep(j, 0, 100001){
                if(dp2[j] == INF) continue;
                int next = j + m2[i].second;
                if(next > 100000) next = 100001;
                chmin(dp2[next], dp2[j] + m2[i].first);
            }
        }
        int MIN = INF;
        repb(i, 100001, 0){
            chmin(MIN, dp[i]);
            dp[i] = MIN;
        }
        MIN = INF;
        repb(i, 100001, 0){
            chmin(MIN, dp2[i]);
            dp2[i] = MIN;
        }
        int ans = INF;
        rep(i, 0, 100001){
            int sum = dp2[i];
            rep(j, 0, n){
                sum += dp[max(0LL, h[j] - i)];
            }
            chmin(ans, sum);
        }
        cout << ans << endl;
    }
}
