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

using ll = long long;
const ll HSIZE=100001;
const ll INF=1e15;

ll solve(int n){
    vector<int> h(n);
    for(int i=0;i<n;i++) cin>>h[i];
    int m;
    cin>>m;
    vector<ll> smp,sdmg;
    vector<ll> amp,admg;
    bool isok=false;
    for(int i=0;i<m;i++){
        string buf,tar;
        int mp,dmg;
        cin>>buf>>mp>>tar>>dmg;
        if(mp==0){
            if(dmg==0) continue;
            isok=true;
        }
        else if(tar=="Single"){
            smp.push_back(mp);
            sdmg.push_back(dmg);
        }
        else{
            amp.push_back(mp);
            admg.push_back(dmg);
        }
        
    }
    if(isok) return 0;
    int N=sdmg.size();
    vector<ll> sdp;
    {
        vector<vector<ll>> tmp(2,vector<ll>(HSIZE,INF));
        tmp[0][0]=0;
        for(int i=0;i<N;i++){
            int fr=i&1;
            int to=(i+1)&1;
            fill(tmp[to].begin(),tmp[to].end(),INF);
            for(int j=0;j<HSIZE;j++){
                tmp[to][j]=min(tmp[to][j],tmp[fr][j]);
                tmp[to][min(j+sdmg[i],HSIZE-1)]=min(tmp[to][min(j+sdmg[i],HSIZE-1)],tmp[to][j]+smp[i]);
            }
        }
        sdp=tmp[N&1];
    }
    N=admg.size();
    vector<ll> adp;
    {
        vector<vector<ll>> tmp(2,vector<ll>(HSIZE,INF));
        tmp[0][0]=0;
        for(int i=0;i<N;i++){
            int fr=i&1;
            int to=(i+1)&1;
            fill(tmp[to].begin(),tmp[to].end(),INF);
            for(int j=0;j<HSIZE;j++){
                tmp[to][j]=min(tmp[to][j],tmp[fr][j]);
                tmp[to][min(j+admg[i],HSIZE-1)]=min(tmp[to][min(j+admg[i],HSIZE-1)],tmp[to][j]+amp[i]);
            }
        }
        adp=tmp[N&1];
    }
    for(int i=HSIZE-2;i>=0;i--){
        sdp[i]=min(sdp[i],sdp[i+1]);
    }
    ll res=ll(1e15);
    for(int i=0;i<HSIZE;i++){
        ll sc=adp[i];
        for(int j=0;j<n;j++){
            sc+=sdp[max(h[j]-i,0)];
        }
        res=min(res,sc);
    }
    return res;
}
int main(){
    int n;
    while(cin>>n,n){
        cout<<solve(n)<<endl;
    }
    return 0;
}
