#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int n, m, a[200], b[200], d[200]; vector<int>v1, v2, w1, w2, dp1, dp2;
vector<int>knapsack(int W, vector<int>v, vector<int>w) {
	vector<int>dp(W + 1000, 999999999);
	for (int i = 0; i < dp.size(); i++) { dp[i] = 999999999; }
	dp[0] = 0;
	for (int i = 0; i < (int)min(v.size(), w.size()); i++) {
		for (int j = v[i]; j <= W; j++)dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
	}
	for (int i = W - 1; i >= 0; i--) {
		dp[i] = min(dp[i], dp[i + 1]);
	}
	return dp;
}
int main() {
	while (true) {
		v1.clear(); v2.clear(); w1.clear(); w2.clear(); dp1.clear(); dp2.clear();
		cin >> n; if (n == 0)break;
		for (int i = 0; i < n; i++)cin >> a[i]; cin >> m;
		for (int i = 0; i < m; i++) {
			string S, T; cin >> S >> b[i] >> T >> d[i]; if (d[i] >= 200000)d[i] = 200000;
			if (d[i] == 0)continue;
			if (T == "Single") { v1.push_back(d[i]); w1.push_back(b[i]); }
			if (T == "All") { v2.push_back(d[i]); w2.push_back(b[i]); }
		}
		dp1 = knapsack(400000, v1, w1);
		dp2 = knapsack(400000, v2, w2);
		if (v1.size() == 0) {
			int maxn = 0; for (int i = 0; i < n; i++)maxn = max(maxn, a[i]);
			cout << dp2[maxn] << endl;
		}
		else {
			int maxn = 999999999;
			for (int i = 0; i <= 300000; i++) {
				int sum = dp2[i];
				for (int j = 0; j < n; j++) {
					if (a[j] > i && dp1[a[j] - i] <= 1e8) {
						sum += dp1[a[j] - i];
					}
				}
				maxn = min(maxn, sum);
			}
			cout << maxn << endl;
		}
	}
	return 0;
}