#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

int main() {
	for (;;) {
		int N; cin >> N;
		if (N == 0) break;
		vector<int> h(N);
		for (int i = 0; i < N; i++)
			cin >> h[i];
		int M; cin >> M;
		vector<string> t(M);
		vector<int> m(M), d(M);
		for (int j = 0; j < M; j++) {
			string s;
			cin >> s >> m[j] >> t[j] >> d[j];
			d[j] = min(d[j], 100000);
		}
		vector<int> dps(100001, INF), dpa(100001, INF);
		dps[0] = dpa[0] = 0;
		for (int j = 0; j < M; j++) {
			vector<int>& dp = (t[j] == "Single" ? dps : dpa);
			for (int k = 0; k < d[j]; k++)
				dp[k] = min(dp[k], m[j]);
			for (int k = d[j]; k <= 100000; k++)
				dp[k] = min(dp[k], dp[k - d[j]] + m[j]);
		}
		ll mini = INF;
		for (int k = 0; k <= 100000; k++) {
			ll sum = dpa[k];
			for (int i = 0; i < N; i++) {
				int x = max(0, h[i] - k);
				sum += dps[x];
			}
			mini = min(mini, sum);
		}
		cout << mini << endl;
	}
}