// Original C++ solution (slower):
#include<iostream>

#include<string>

#include<string.h>

#include<map>

using namespace std;



#define REP(i,a,b) for(i=a; i<b; ++i)

#define rep(i,n) REP(i,0,n)



long long hp[100];

long long dp1[100050];

long long dp2[100050];

const long long inf = 1<<29;

pair<long long, long long> smagic[100];

pair<long long, long long> amagic[100];



int main() {

    int N,M,i,j,k,mp,dm,am,sm;

    long long maxhp;

    string name,range;

    while(cin>>N, N) {

        memset(hp, 0, sizeof(hp));

        rep(i,100005) dp1[i] = dp2[i] = inf;

        am = sm = maxhp = 0;

        rep(i,N) cin>>hp[i];

        rep(i,N) maxhp = max(maxhp, hp[i]);

        cin>>M;



        rep(i,M) {

            cin>>name>>mp>>range>>dm;

            if(range == "All") {

                amagic[am] = make_pair(mp,dm);

                am++;

            }else{

                smagic[sm] = make_pair(mp,dm);

                sm++;

            }

        }



        dp1[0] = dp2[0] = 0;

        rep(i,maxhp+1) {

            rep(j,am) {

                if(dp1[i] == inf) continue;

                long long h = min(maxhp, i+amagic[j].second);

                dp1[h] = min(dp1[h],

                             dp1[i]+amagic[j].first);

            }

            rep(j,sm) {

                if(dp2[i] == inf) continue;

                int h = min(maxhp, i+smagic[j].second);

                dp2[h] = min(dp2[h],

                             dp2[i]+smagic[j].first);

            }

        }





        int smax = inf,amax = inf;

        for(i = 100004; i>=0; --i) {

            if(smax > dp2[i]) smax = dp2[i];

            if(amax > dp1[i]) amax = dp1[i];

            if(dp2[i] > smax) dp2[i] = smax;

            if(dp1[i] > amax) dp1[i] = amax;

        }



        long long ans = inf;

        for(int i=maxhp; i>=0; --i) {

            //cout<<i<<" "<<ans<<endl;

            int j;

            long long tmp = dp1[i];

            rep(j,N) {

                if(hp[j]-i > 0) {

                    //if(i == 98495) cout<<hp[j]-i<<" "<<j<<" "<<dp2[hp[j]-i]<<endl;

                    tmp += dp2[hp[j]-i];

                }

            }

            //cout<<ans<<" "<<tmp<<endl;

            // if(ans > tmp) {

            //     cout<<i<<" "<<ans<<" "<<tmp<<endl;

            // }

            ans = min(tmp, ans);

        }



        cout<<ans<<endl;

    }

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<string>

#include<string.h>

#include<map>

using namespace std;



#define REP(i,a,b) for(i=a; i<b; ++i)

#define rep(i,n) REP(i,0,n)



typedef long long ll;

int hp[100];

int dp1[100050];

int dp2[100050];

const int inf = 1<<29;

pair<int, int> smagic[100];

pair<int, int> amagic[100];



int main() {

    int N,M,i,j,k,mp,dm,am,sm,maxhp;

    string name,range;

    while(cin>>N, N) {

        memset(hp, 0, sizeof(hp));

        rep(i,100005) dp1[i] = dp2[i] = inf;

        am = sm = maxhp = 0;

        rep(i,N) cin>>hp[i];

        rep(i,N) maxhp = max(maxhp, hp[i]);

        cin>>M;



        rep(i,M) {

            cin>>name>>mp>>range>>dm;

            if(range == "All") {

                amagic[am] = make_pair(mp,dm);

                am++;

            }else{

                smagic[sm] = make_pair(mp,dm);

                sm++;

            }

        }



        dp1[0] = dp2[0] = 0;

        rep(i,maxhp+1) {

            rep(j,am) {

                if(dp1[i] == inf) continue;

                int h = min(maxhp, i+amagic[j].second);

                dp1[h] = min(dp1[h],

                             dp1[i]+amagic[j].first);

            }

            rep(j,sm) {

                if(dp2[i] == inf) continue;

                int h = min(maxhp, i+smagic[j].second);

                dp2[h] = min(dp2[h],

                             dp2[i]+smagic[j].first);

            }

        }





        int smax = inf,amax = inf;

        for(i = 100004; i>=0; --i) {

            if(smax > dp2[i]) smax = dp2[i];

            if(amax > dp1[i]) amax = dp1[i];

            if(dp2[i] > smax) dp2[i] = smax;

            if(dp1[i] > amax) dp1[i] = amax;

        }



        ll ans = inf;

        for(int i=maxhp; i>=0; --i) {

            int j;

            ll tmp = dp1[i];

            rep(j,N) {

                if(hp[j]-i > 0) {

                    tmp += dp2[hp[j]-i];

                }

            }

            ans = min(tmp, ans);

        }



        cout<<ans<<endl;

    }

}

// Fastest known solution for this problem: