#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int N;
int HP[101];

int M;

vector< tuple<int, int, int> > magic;

int dp[2][1000001]; // Single/All???just i???????????????????????????????°????MP

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> N, N) {
    magic.clear();

    int mxhp = 0;
    rep(i, N) cin >> HP[i], mxhp = max(mxhp, HP[i]);

    cin >> M;
    rep(i, M) {
      string na, tar;
      int mp, dam;
      cin >> na >> mp >> tar >> dam;
      magic.emplace_back(mp, (tar == "All"), dam);
    }

    fill(dp[0], dp[2], inf);
    dp[0][0] = dp[1][0] = 0;
    for(auto m : magic) {
      int mp, tar, dam;
      tie(mp, tar, dam) = m;
      rep(i, mxhp+1) {
	dp[tar][min(mxhp, i+dam)] = min(dp[tar][min(mxhp, i+dam)], dp[tar][i] + mp);
      }
    }

    for(int i = mxhp; i > 0; i--) {
      if(dp[0][i] < dp[0][i-1]) dp[0][i-1] = dp[0][i];
    }

    int ans = inf;
    rep(i, mxhp+1) if(dp[1][i] != inf) {
      int sum = dp[1][i];
      rep(j, N) sum += dp[0][max(HP[j]-i, 0LL)];
      ans = min(ans, sum);
    }
    cout << ans << endl;
  }

  return 0;
}