import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

struct Magic {
    int range; /* 0 : single, 1 : all */
    int cost, damage;
}

int N, M;
int[] HP;
Magic[] Ms;

bool input() {
    scanf("%d\n", &N);
    if (N == 0) return false;
    HP = new int[N];
    foreach (i; 0 .. N) {
        scanf("%d\n", &HP[i]);
    }
    scanf("%d\n", &M);
    Ms = new Magic[M];
    foreach (i; 0 .. M) {
        string name, target;
        int mp, damage;
        readf("%s %d %s %d\n", &name, &mp, &target, &damage);
        Ms[i] = Magic(target == "All", mp, damage);
    }
    return true;
}

void solve() {
    Magic[] As, Ss;
    foreach (m; Ms) {
        ( m.range ? As : Ss ) ~= m;
    }

    const P = 100000;
    auto dp = new int[P + 1];
    dp[] = int.max / 2;
    dp[0] = 0;
    foreach (i, a; As) {
        foreach (j; 0 .. P + 1) {
            if (j + a.damage > P) continue;
            dp[j + a.damage] = min(dp[j + a.damage], dp[j] + a.cost);
        }
    }

    auto dp2 = new int[P + 1];
    dp2[] = int.max / 2;
    dp2[0] = 0;
    foreach (s; Ss) {
        foreach (i; 0 .. P + 1) {
            if (i + s.damage > P) continue;
            dp2[i + s.damage] = min(dp2[i + s.damage], dp2[i] + s.cost);
        }
    }

    foreach_reverse (i; 0 .. P) {
        dp2[i] = min(dp2[i], dp2[i + 1]);
    }

    int ans = int.max / 2;
    foreach (i; 0 .. P + 1) {
        int x = dp[i];
        foreach (j; 0 .. N) {
            if (HP[j] <= i) continue;
            x += dp2[ HP[j] - i ];
        }
        ans = min(ans, x);
    }
    writeln(ans);
}

void main() {
    while (input) solve;
}