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

const int MAXN = 101;
const int MAXD = 200001;
const int INF = 1<<28;
int N, A, S;
int HP[MAXN];
int aMP[MAXN], aDM[MAXN];
int sMP[MAXN], sDM[MAXN];
int aDP[MAXD], sDP[MAXD];

void calc(int n, int w[MAXN], int cost[MAXN], int dp[MAXD]) {
  fill(dp, dp+MAXD, INF);
  dp[0] = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = w[i]; j < MAXD; ++j) {
      dp[j] = min(dp[j], dp[j-w[i]] + cost[i]);
    }
  }
}

int main() {
  while(cin >> N && N) {
    for(int i = 0; i < N; ++i) cin >> HP[i];
    int M; cin >> M;
    A = S = 0;
    for(int i = 0; i < M; ++i) {
      string name, target;
      int mp, damage;
      cin >> name >> mp >> target >> damage;
      damage = min(damage, 100000);
      if(damage == 0) continue;
      if(target == "All") {
        aMP[A] = mp;
        aDM[A] = damage;
        ++A;
      } else {
        sMP[S] = mp;
        sDM[S] = damage;
        ++S;
      }
    }
    calc(A, aDM, aMP, aDP);
    calc(S, sDM, sMP, sDP);
    for(int i = MAXD-1; i-1 >= 0; --i)
      sDP[i-1] = min(sDP[i-1], sDP[i]);
    int res = INF;
    for(int i = 0; i < MAXD; ++i) {
      int sum = aDP[i];
      if(sum == INF) continue;
      for(int j = 0; j < N; ++j) {
        if(sDP[max(0, HP[j]-i)] == INF) {
          sum = INF;
          continue;
        }
        sum += sDP[max(0, HP[j]-i)];
      }
      res = min(res, sum);
    }
    cout << res << endl;
  }
  return 0;
}