const LL inf=2e9;
const int MAXN=3e5+5;
map<pair<int,int>,int>mp;
struct Node{
int u,v;
int type;
bool operator < (const Node &b)const{
if(u!=b.u)
return u<b.u;
else if(v!=b.v)
return v<b.v;
else
return type<b.type;
}
};
map<Node,LL> cost;
vector<int> c[MAXN];
int a[MAXN];
LL ans;
void solve(int id,int u,int v){
LL w1,w2,w3,w4;
int cnt[2]={0,0};
w1=cost.count(Node{u,v,0})?cost[Node{u,v,0}]:inf;
w2=cost.count(Node{u,v,1})?cost[Node{u,v,1}]:inf;
w3=cost.count(Node{v,u,0})?cost[Node{v,u,0}]:inf;
w4=cost.count(Node{v,u,1})?cost[Node{v,u,1}]:inf;
w1=min(w1,w2);
w3=min(w3,w4);
for(int t:c[id]){
if(t==0){
if(cnt[1]){
if(w4==min(w2,w4)&&w4<w3+w1){
ans+=w4;
cnt[1]--;
}
else
cnt[0]++;
}
else
cnt[0]++;
}
else{
if(cnt[0]){
if(w2==min(w2,w4)&&w2<w1+w3){
ans+=w2;
cnt[0]--;
}
else
cnt[1]++;
}
else
cnt[1]++;
}
}
int tt=min(cnt[0],cnt[1]);
if(w2!=min(w2,w4)&&w2<w1+w3){
ans+=1LL*tt*w2;
cnt[0]-=tt;
cnt[1]-=tt;
}
else if(w4!=min(w2,w4)&&w4<w3+w1){
ans+=1LL*tt*w4;
cnt[0]-=tt;
cnt[1]-=tt;
}
ans+=1LL*cnt[0]*w1+1LL*cnt[1]*w3;
}
int main(){
int n=read_int(),d=read_int();
_for(i,0,d)a[i]=read_int();
_for(i,1,d){
int x=a[i-1],y=a[i];
if(x>y)swap(x,y);
if(mp.find(make_pair(x,y))==mp.end()){
int t=mp.size();
mp[make_pair(x,y)]=t;
}
c[mp[make_pair(x,y)]].push_back(a[i-1]>a[i]);
}
int m=read_int();
_for(i,0,m){
int u=read_int(),v=read_int();
char type=get_char();
LL w=read_int();
Node t;
if(type=='O')
t=Node{u,v,0};
else
t=Node{u,v,1};
if(cost.find(t)==cost.end())
cost[t]=inf;
cost[t]=min(cost[t],w);
}
for(map<pair<int,int>,int>::iterator iter=mp.begin();iter!=mp.end();iter++){
pair<int,int> temp=iter->first;
solve(iter->second,temp.first,temp.second);
}
enter(ans);
return 0;
}