# 【状压dp】校长的烦恼UVA10817

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#define INF (21000010)
using namespace std;
int S,M,N,T[2020],val[2020],A[2020],dp[125][(1<<8)+5][(1<<8)+5];
bool vis[125][(1<<9)+5][(1<<9)+5];
void InIt(){
memset(T,0,sizeof(T));
int i,x=0; char ch;
while (1){
ch=getchar();
if (ch=='\n') break;
if (ch!=' ') x=(x<<3)+(x<<1)+ch-'0';
else if (x) T[++T[0]]=x,x=0;
}
if (x)  T[++T[0]]=x;
}
int Dfs(int i,int s0,int s1){
int &ans=dp[i][s0][s1];
if (vis[i][s0][s1]) return ans;
vis[i][s0][s1]=1;
if (!s0&&!s1&&i>M) return ans=0;
//坑点，此处不能直接退，因为固定教师一定要用
if (i==N+M+1) return ans=INF;

if (i>M) ans=min(ans,Dfs(i+1,s0,s1));
int m0=A[i]&s0,m1=A[i]&s1;
//m0：能使没人教变成有一个人教的科目集合
//m1: 能使一个人教变成至少两个人教的科目集合
s0^=m0; s1^=m1; s1|=m0;
ans=min(ans,Dfs(i+1,s0,s1)+val[i]);
return ans;
}
void Work(){
int i,j;
memset(A,0,sizeof(A));
memset(vis,0,sizeof(vis));
memset(dp,127/3,sizeof(dp));
for (i=1;i<=M+N;i++){
InIt();
val[i]=T[1];
for (j=2;j<=T[0];j++) A[i]|=(1<<(T[j]-1));
}
printf("%d\n",Dfs(1,(1<<S)-1,0));//写成（1<<M）-1
}
int main(){
while (1){
scanf("%d %d %d",&S,&M,&N);
if (!S&&!M&&!N) break;
char ch=0;
while (ch!='\n') ch=getchar();
Work();
}
}