#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e17
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  //ios::sync_with_stdio(false);
  while(1){
    int n,m;
    int mxhp=0;
    cin>>n;
    if(n==0) break;
    int a[n];
    rep(i,n){cin>>a[i];mxhp=max(mxhp,a[i]);}
    cin>>m;
    string s[m];
    int mana[m],damage[m];
    rep(i,m){
      cin>>s[i]>>mana[i]>>s[i]>>damage[i];
      if(damage[i]>100009) damage[i]=100009;
    }
    int dps[100010],dpm[100010];
    rep(i,100010) dps[i]=dpm[i]=INF;
    dps[0]=0;dpm[0]=0;
    rep(i,100010){
      rep(j,m){
	if(i+damage[j]<100010){
	  if(s[j]=="Single" && dps[i]!=INF){
	    dps[i+damage[j]]=min(dps[i+damage[j]],dps[i]+mana[j]);
	  }else if(s[j]=="All" && dpm[i]!=INF){
	    dpm[i+damage[j]]=min(dpm[i+damage[j]],dpm[i]+mana[j]);
	  }
	}else{
	  if(s[j]=="Single" && dps[i]!=INF){
	    dps[100009]=min(dps[100009],dps[i]+mana[j]);
	  }else if(s[j]=="All" && dpm[i]!=INF){
	    dpm[100009]=min(dpm[100009],dpm[i]+mana[j]);
	  }
	}
      }
    }
    
    repn(i,100008){
      dps[i]=min(dps[i],dps[i+1]);
      dpm[i]=min(dpm[i],dpm[i+1]);
      
    }
    
    int ans=INF;
    rep(i,mxhp+1){
      int cnt=0;
      cnt+=dpm[i];
      rep(j,n){
	cnt+=dps[max((int)0,a[j]-i)];
      }
      ans=min(cnt,ans);
    }
    cout<<ans<<endl;
  }
      

  return 0;
}

