#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

inline void chmin(int &a, int b) { a = min(a,b); }
inline void chmax(int &a, int b) { a = max(a,b); }

const int INF = (int)1e9 + 7;
int N, M;
vector<int> HP;
enum { Single, All };
struct magic { int mp, dmg, type; };    // Single, All
vector<magic> spells;

int solve() {
    int max_hp = *max_element(HP.begin(), HP.end());
    vector<vector<int>> dp(2, vector<int>(max_hp + 1, INF));
    for (int i = 0; i < 2; i++) dp[i][0] = 0;
    for (magic e : spells) {
        for (int i = 0; i < max_hp; i++) {
            chmin(dp[e.type][min(max_hp, i + e.dmg)], dp[e.type][i] + e.mp);
        }
    }
    for (int i = max_hp; i > 0; i--) {
        chmin(dp[Single][i - 1], dp[Single][i]);
    }
    int ans = INF;
    for (int dmg = 0; dmg <= max_hp; dmg++) {
        int tmp = dp[All][dmg];
        for (int hp : HP) {
            tmp = min(INF, tmp + dp[Single][max(hp - dmg, 0)]);
        }
        chmin(ans, tmp);
    }
    return ans;
}

bool input() {
    cin >> N;
    if (!N) return 0;
    HP.resize(N);
    for (int& e : HP) cin >> e;
    cin >> M;
    spells.resize(M);
    for (magic& e : spells) {
        string name, tgt;
        cin >> name >> e.mp >> tgt >> e.dmg;
        e.type = tgt == "All";
    }
    return 1;
}

signed main() {
    while (input()) cout << solve() << endl;
    return 0;
}
