#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;

namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

int dp1[100010];
int dp2[100010];
void mainmain(){
	int n;
	int m;
	while(cin>>n,n){
		vint hp(n);
		rep(i,n) cin>>hp[i];
		cin>>m;
		vector<pii> one,all;
		rep(i,m){
			string s;
			cin>>s;
			int a,b;
			cin>>a>>s>>b;
			if(s=="Single"){
				one.PB(mkp(a,b));
			}
			else{
				all.PB(mkp(a,b));
			}
		}
		// cout<<"aaa\n";
		rep(i,100010){
			dp1[i]=INF;
			dp2[i]=INF;
		}
		dp1[0]=0;
		// cout<<"size "<<(int)one.size()<<endl;
		rep(i,one.size()){
			int t=INF;
			rep(j,100010){
				if(j+one[i].S>=100010){
					if(j==0){
						t=0;
					}
					dp1[100009]=min(dp1[100009],t+one[i].F);
					break;
				}
				if(dp1[j]==INF) continue;
				// if(dp1[j]+one[i].F<0) continue;
				dp1[j+one[i].S]=min(dp1[j+one[i].S],dp1[j]+one[i].F);
				if(j+one[i].S*2>=100010) t=min(t,dp1[j+one[i].S]);
			}
		}
		int M=INF;
		for(int i=100009;i>=0;i--){
			// if(dp1[i]!=INF) cout<<"dp1"<<" "<<i<<" "<<dp1[i]<<endl;
			dp1[i]=min(dp1[i],M);
			M=min(dp1[i],M);
		}
		dp2[0]=0;
		rep(i,all.size()){
			// cout<<i<<endl;
			int t=INF;
			rep(j,100010){
				if(j+all[i].S>=100010){
					if(j==0){
						t=0;
					}
					dp2[100009]=min(dp2[100009],t+all[i].F);
					break;
				}
				if(dp2[j]==INF) continue;
				// if(dp2[j]+all[i].F<0) continue;
				dp2[j+all[i].S]=min(dp2[j+all[i].S],dp2[j]+all[i].F);
				if(j+all[i].S*2>=100010) t=min(t,dp2[j+all[i].S]);
			}
			// cout<<t<<endl;
		}
		M=INF;
		for(int i=100009;i>=0;i--){
			dp2[i]=min(dp2[i],M);
			M=min(dp2[i],M);
			// if(i<100) cout<<"dp2 "<<i<<" "<<dp2[i]<<endl;
		}
		// cout<<"M "<<M<<endl;
		// cout<<"hoge\n";
		int ans=INF;
		rep(i,100010){
			int tmp=dp2[i];
			rep(j,n){
				if(hp[j]<=i) continue;
				tmp+=dp1[hp[j]-i];
			}
			ans=min(ans,tmp);
		}
		// cout<<"dp1\n";
		// rep(i,50){
			// cout<<i<<" "<<dp1[i]<<endl;
		// }
		// cout<<"dp2"<<endl;
		// rep(i,50){
			// cout<<i<<" "<<dp2[i]<<endl;
		// }
		// cout<<ans<<endl;
		// cout<<dp1[100000]<<endl;
		// rep(i,n){
			// if(hp[i]-40221*3>0) cout<<hp[i]-40221*3<<endl;
		// }
		cout<<ans<<endl;
	}

}

}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 2000