#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int n, m;

void solve(){
    int hp[n];
    rep(i, n) scanf("%d", &hp[i]);
    scanf("%d", &m);
    vector<pii> single, all; // (mp, damage)
    rep(_, m){
        string name, target;
        lint mp, damage;
        cin >> name >> mp >> target >> damage;
        if(target == "Single") single.emplace_back(mp, damage);
        else all.emplace_back(mp, damage);
    }

    lint all_cost[MAX];
    fill(all_cost, all_cost + MAX, INF);
    all_cost[0] = 0;
    rep(i, all.size()){
        rep(j, MAX)if(all_cost[j] < INF){
            chmin(all_cost[min(MAX - 1, j + all[i].se)], min(INF, all_cost[j] + all[i].fi));
        }
    }

    lint single_cost[MAX];
    fill(single_cost, single_cost + MAX, INF);
    single_cost[0] = 0;
    rep(i, single.size()){
        rep(j, MAX)if(single_cost[j] < INF){
            chmin(single_cost[min(MAX - 1, j + single[i].se)], min(INF, single_cost[j] + single[i].fi));
        }
    }
    rrep(i, MAX - 1) chmin(single_cost[i], single_cost[i + 1]);
    
    lint ans = INF;
    rep(all_damage, MAX){
        lint tmp = all_cost[all_damage];
        rep(i, n){
            tmp += single_cost[max(0, hp[i] - all_damage)];
            chmin(tmp, INF);
        }
        chmin(ans, tmp);
    }
    printf("%lld\n", ans);
}

int main(){
    while(scanf("%d", &n) && n){
        solve();
    }
}
