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

const int MAX = 1e6;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	while (cin >> N, N) {
		vector<int> hp(N);
		for (int i = 0; i < N; i++) {
			cin >> hp[i];
		}
		sort(hp.begin(), hp.end());
		int M;
		cin >> M;
		vector<ll> dp_s(MAX + 1, 1e17);
		vector<ll> dp_a(MAX + 1, 1e17);
		dp_s[0] = dp_a[0] = 0;
		for (int i = 0; i < M; i++) {
			string sp, ta;
			int mp, dm;
			cin >> sp >> mp >> ta >> dm;
			if (ta == "Single") {
				for (int i = 0; i <= MAX; i++) {
					int t = min(MAX, i + dm);
					dp_s[t] = min(dp_s[t], dp_s[i] + mp);
				}
				for (int i = MAX - 1; i >= 0; i--) {
					dp_s[i] = min(dp_s[i + 1], dp_s[i]);
				}
			}
			else {
				for (int i = 0; i <= MAX; i++) {
					int t = min(MAX, i + dm);
					dp_a[t] = min(dp_a[t], dp_a[i] + mp);
				}
				for (int i = MAX - 1; i >= 0; i--) {
					dp_a[i] = min(dp_a[i + 1], dp_a[i]);
				}
			}
		}
		ll res = LLONG_MAX;
		for (int i = 0; i <= MAX; i++) {
			ll val = dp_a[i];
			for (int j = 0; j < N; j++) {
				val += dp_s[max(0, hp[j] - i)];
			}
			res = min(res, val);
		}
		cout << res << endl;
	}
	return 0;
}

