#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000007
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<long long,int> P;

int n, M;
int hp[100];
P x[2][100];
long long dp[2][100001];

void solve(){
	rep(i,n) cin >> hp[i];
	rep(i,2) for(int j = 0; j <= 100000; j++) dp[i][j] = INF;
	dp[0][0] = 0; dp[1][0] = 0;
	cin >> M;
	int m[2] = {0,0};
	rep(i,M){
		string na, tar;
		int mp, dam, u = 0;
		cin >> na >> mp >> tar >> dam;
		if(tar[0] == 'A') u = 1;
		x[u][m[u]] = P(mp,dam);
		m[u]++;
	}
	rep(u,2){
		rep(i,m[u]){
			P p = x[u][i];
			for(int j = 0; j <= 100000; j++){
				if(j < p.second) dp[u][j] = min(dp[u][j],p.first);
				else dp[u][j] = min(dp[u][j],dp[u][j-p.second]+p.first);
			}
		}
	}
	long long ans = INF;
	for(int i = 0; i <= 100000; i++){
		long long cnt = dp[1][i];
		rep(j,n){
			if(hp[j]-i <= 0) continue;
			int h = hp[j]-i;
			cnt += dp[0][h];
		}
		ans = min(ans,cnt);
	}
	cout << ans << endl;
}

int main(){
	while(true){
		cin >> n;
		if(n == 0) break;
		solve();
	}
}