#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef struct Mag
{
	int MP,tag,Dam;//single:0 all:1
	bool operator < (const Mag &A)const{return tag==A.tag?A.MP>MP:tag<A.tag;}
}Mag;

int N,M,HP[105],A,SDP[100005],ADP[100005],res,tmp;
Mag SP[105];

int main()
{
	for(;scanf("%d",&N),N;)
	{
		res=1000000000;
		A=0;
		memset(SDP,0x7f,sizeof(SDP));
		memset(ADP,0x7f,sizeof(ADP));
		SDP[0]=ADP[0]=0;
		for(int i=0;i<N;i++)scanf("%d",HP+i);
		scanf("%d\n",&M);
		for(int i=0;i<M;i++)
		{
			char t[20];
			scanf("%*s%d%s%d\n",&SP[i].MP,t,&SP[i].Dam);
			A+=SP[i].tag=t[0]=='S'?0:1;
		}
		sort(SP,SP+M);
		for(int i=0;i<M-A;i++)
		{
			for(int j=0;j<=100000;j++)
			{
				int np=j+SP[i].Dam;
				if(np>100000)np=100000;
				SDP[np]=min(SDP[np],SDP[j]+SP[i].MP);
			}
		}
		for(int i=100000;i>=0;i--)
			SDP[i]=min(SDP[i],SDP[i+1]);

		for(int i=M-A;i<M;i++)
		{
			for(int j=0;j<=100000;j++)
			{
				int np=j+SP[i].Dam;
				if(np>100000)np=100000;
				ADP[np]=min(ADP[np],ADP[j]+SP[i].MP);
			}
		}
		if(A==M)
		{
			int mh=0;
			for(int i=0;i<N;i++)mh=max(mh,HP[i]);
			for(int i=mh;i<=100000;i++)
				res=min(res,ADP[i]);
		}
		else
		{
			for(int i=0;i<=100000;i++)
			{
				if(ADP[i]==2139062143)continue;
				tmp=ADP[i];
				for(int k=0;k<N;k++)
				{
					if(HP[k]-i>=0)
					{
						int np=HP[k]-i;
						if(np<0)np=0;
						if(SDP[np]==2139062143)
						{
							tmp=1000000000;
							break;
						}
						tmp+=SDP[np];
					}
				}
				res=min(res,tmp);
			}
		}
		printf("%d\n",res);
	}
	return 0;
}