RT
/*
*Author: Hughpig
*made in China
*/
#include<bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include<atcoder/all>
using namespace atcoder;
#endif
#define ll long long
#define up(l,r,i) for(int i=(l);(i)<=(r);++i)
#define vi vector<ll>
#define pii pair<ll,ll>
#define pb push_back
#define pob pop_back
#define gc getchar
#define pc putchar
#define il inline
#define all(x) x.begin(),x.end()
#define reg register
#define loop while(1)
#define debug cout<<"QwQ\n"
#define Sort(a) sort(a.begin(), a.end())
void file(string fl) {
freopen((fl+".in").c_str(),"r",stdin);
freopen((fl+".out").c_str(),"w",stdout);
}
il ll read()
{
char ch=gc();
ll s=0,w=1;
while(ch<'0'||ch>'9')
{
if(ch=='-'){w=-1;}
ch=gc();
}
while(ch>='0'&&ch<='9')
{
s=(s<<1)+(s<<3)+ch-48;
ch=gc();
}
return w*s;
}
il void write(ll x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)write(x/10);
putchar(x%10+'0');
}
ll ksm(ll a,ll b,ll p)
{
ll ans=1%p;
for(;b;b>>=1){
if(b&1) ans=ans*a%p;
a=a*a%p;
}
return ans;
}
void ios_optimize(){ios::sync_with_stdio(0);cin.tie(0);}
ll ls(ll u){return u<<1;}
ll rs(ll u){return u<<1|1;}
ll myabs(ll x){return x>0?x:-x;}
ll mymax(ll x,ll y){return x>y?x:y;}
ll mymin(ll x,ll y){return x<y?x:y;}
ll lowbit(ll n){return n&-n;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
ll inv(ll a,ll p){return ksm(a,p-2,p);}
void yn(bool f){cout<<(f?"Yes\n":"No\n");}
constexpr int N=2e5+9;
constexpr int mod1=998244353,mod2=1e9+7;
constexpr int inf=1e9;
constexpr ll INF=1e18;
constexpr double eps=1e-9;
int n,ans=inf;
bool vis[114];
struct edge{
int n1,n2,val;
vector<int> l,r;
}a[107];
void dfs(int p,int sum,bool dir,int fa){
if(sum>ans)return;
if(p==fa){
ans=sum;
return;
}
if(dir){
for(auto x:a[p].l){
if(!vis[x]){
vis[x]=1;
dfs(x,sum+a[x].val,dir^1,fa);
}
}
}
else{
for(auto x:a[p].r){
if(!vis[x]){
vis[x]=1;
dfs(x,sum+a[x].val,dir^1,fa);
}
}
}
}
int main()
{
ios_optimize();
int TestCases=1;
//cin>>TestCases;
while(TestCases--){
cin>>n;
up(1,n,i){
int s;
cin>>s;
cin>>a[i].val>>a[i].n1>>a[i].n2;
up(1,a[i].n1,j){
int x;cin>>x;
a[i].l.pb(x);
}
up(1,a[i].n2,j){
int x;cin>>x;
a[i].r.pb(x);
}
}
up(1,n,i){
memset(vis,0,sizeof(vis));
for(auto x:a[i].l){
vis[x]=1;
dfs(x,a[i].val,0,i);
vis[x]=0;
}
}
cout<<ans;
}
return 0;
}