#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
int read()
{
int x=0,f=1; char ch=getchar();
while (ch<‘0‘ || ch>‘9‘) {if (ch==‘-‘) f=-1; ch=getchar();}
while (ch>=‘0‘ && ch<=‘9‘) {x=x*10+ch-‘0‘; ch=getchar();}
return x*f;
}
#define maxm 3000010
#define maxn 3010
int n,m,tot;
struct EdgeNode{int next,to,cap;}edge[maxm];
int head[maxn],cnt=1;
void add(int u,int v,int w) {cnt++; edge[cnt].next=head[u]; head[u]=cnt; edge[cnt].to=v; edge[cnt].cap=w;}
void insert(int u,int v,int w) {add(u,v,w); add(v,u,0);}
#define inf 0x7fffffff
int dis[maxn],cur[maxn],S,T;
bool bfs()
{
queue<int>q;
for (int i=S; i<=T; i++) dis[i]=-1;
q.push(S); dis[S]=0;
while (!q.empty())
{
int now=q.front(); q.pop();
for (int i=head[now]; i; i=edge[i].next)
if (edge[i].cap && dis[edge[i].to]==-1)
dis[edge[i].to]=dis[now]+1,q.push(edge[i].to);
}
return dis[T]!=-1;
}
int dfs(int x,int low)
{
if (x==T) return low;
int used=0,w;
for (int i=cur[x]; i; i=edge[i].next)
if (edge[i].cap && dis[edge[i].to]==dis[x]+1)
{
w=dfs(edge[i].to,min(edge[i].cap,low-used));
edge[i].cap-=w; edge[i^1].cap+=w; used+=w;
if (edge[i].cap) cur[x]=i; if (low==used) return used;
}
if (!used) dis[x]=-1;
return used;
}
int dinic()
{
int tmp=0;
while (bfs())
{
for (int i=S; i<=T; i++) cur[i]=head[i];
tmp+=dfs(S,inf);
}
return tmp;
}
int a[maxn],b[maxn];
int main()
{
n=read();
for (int x,i=1; i<=n; i++) a[i]=read(),tot+=a[i];
for (int x,i=1; i<=n; i++) b[i]=read(),tot+=b[i];
m=read();
S=0,T=n+2*m+1;
for (int i=1; i<=n; i++) insert(S,i,a[i]),insert(i,T,b[i]);
for (int nn,x,y,i=1; i<=m; i++)
{
nn=read(); x=read(),y=read(); tot+=x+y;
insert(S,++n,x); insert(++n,T,y);
for (int z,j=1; j<=nn; j++) z=read(),insert(z,n,inf),insert(n-1,z,inf);
}
printf("%d\n",tot-dinic());
return 0;
}