#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;

const int MAX_N=110,MAX_H=1e5+10;

int N,M;
int H[MAX_N],MP[MAX_N],T[MAX_N],D[MAX_N];

void solve(){
    vector<int> dp0(MAX_H,INF),dp1(MAX_H,INF);
    dp0[0]=dp1[0]=0;
    for (int i=0;i<MAX_H;++i){
        for (int j=0;j<M;++j){
            if (!T[j]){
                int nxt=min(MAX_H-1,i+D[j]);
                dp0[nxt]=min(dp0[nxt],dp0[i]+MP[j]);
            } else {
                int nxt=min(MAX_H-1,i+D[j]);
                dp1[nxt]=min(dp1[nxt],dp1[i]+MP[j]);
            }
        }
    }
    for (int i=MAX_H-2;i>=0;--i){
        dp0[i]=min(dp0[i],dp0[i+1]);
        dp1[i]=min(dp1[i],dp1[i+1]);
    }
    int ans=INF;
    for (int i=0;i<MAX_H;++i){
        int sum=dp1[i];
        for (int j=0;j<N;++j){
            sum+=dp0[max(0,H[j]-i)];
            if (ans<sum) break;
        }
        ans=min(ans,sum);
    }
    cout << ans << '\n';
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N,N){
        for (int i=0;i<N;++i) cin >> H[i];
        cin >> M;
        for (int i=0;i<M;++i){
            string S,Tar; cin >> S >> MP[i] >> Tar >> D[i];
            T[i]=(Tar=="All");
        }
        solve();
    }
}
