#include<bits/stdc++.h>
using namespace std ;
vector<int>G[300] ;
bool vis[300][300] ;
int dist[300][300] ;
int P[300] ;
struct triple {
int u , v , w ;
triple() {}
triple( int _u , int _v , int _w ) {
u = _u ;
v = _v ;
w = _w ;
}
};
int M ;
int Back_Track(int src,int sink) {
int parent = P[sink] ;
M = min( M , dist[parent][sink] );
if( parent == src ){
dist[parent][sink] -= M ;
dist[sink][parent] += M ;
return M ;
}
int ret = Back_Track( src , parent ) ;
dist[parent][sink] -= ret ;
dist[sink][parent] += ret ;
return M ;
}
int Find_Aug_Path(int src, int sink) {
memset( P , 0 , sizeof P ) ;
queue<int>Q ;
Q.push( src ) ;
P[src] = src ;
while( !Q.empty() ) {
int nSrc = Q.front() ;
Q.pop() ;
int l = G[nSrc].size() ;
for( int i = 0 ; i < l ; i++ ) {
int v = G[nSrc][i] ;
if( P[v] == 0 && dist[nSrc][v] > 0 ) {
P[v] = nSrc ;
Q.push( v ) ;
if( v == sink ) {
M = 1 << 30 ;
return Back_Track(src,sink) ;
}
}
}
}
return 0 ;
}
int Edmonds_Karp(int src,int sink) {
int ans = 0 ;
int tmp = Find_Aug_Path( src , sink ) ;
ans += tmp ;
while( tmp ) {
tmp = Find_Aug_Path( src , sink ) ;
ans += tmp ;
}
return ans ;
}
int main() {
int cases , caseno = 1 ;
scanf("%d",&cases ) ;
while( cases -- ) {
int n ;
scanf("%d",&n) ;
int temp[n+1] ;
for( int i = 1 ; i<= n ; i++ ) {
scanf("%d",&temp[i]) ;
}
int e ;
scanf("%d",&e) ;
triple T[e] ;
for( int i = 0 ; i < e ; i++ ) {
int u , v , w ;
scanf("%d%d%d",&u,&v,&w) ;
T[i] = triple( u , v , w );
}
int nsrc , nsink ;
scanf("%d%d",&nsrc,&nsink) ;
set<int> SRC ;
set<int> SINK ;
for( int i = 0 ; i < nsrc ; i++ ) {
int tmp ;
scanf("%d",&tmp) ;
SRC.insert(tmp) ;
}
for( int i = 0 ; i < nsink ; i++ ) {
int tmp ;
scanf("%d",&tmp) ;
SINK.insert(tmp) ;
}
memset(dist , 0 , sizeof dist ) ;
memset(vis , 0 , sizeof vis ) ;
for( set<int>::iterator it = SRC.begin() ; it != SRC.end() ; it++ ) {
if( vis[0][*it] == 0 ) {
G[0].push_back( *it ) ;
vis[0][*it] = 1 ;
}
dist[0][*it] += temp[*it] ;
}
for( set<int>::iterator it = SINK.begin() ; it != SINK.end() ; it++ ) {
if( vis[*it][250] == 0 ) {
G[*it].push_back( 250 ) ;
vis[*it][250] = 1 ;
}
dist[*it][250] += temp[*it] ;
}
for( int i = 0 ; i < e ; i++ ) {
if(SRC.find(T[i].u)==SRC.end() ) {
if( vis[T[i].u][T[i].u+120] == 0 ) {
vis[T[i].u][T[i].u+120] = 1 ;
G[T[i].u].push_back( T[i].u+120) ;
G[T[i].u+120].push_back( T[i].u ) ;
G[T[i].u+120].push_back( T[i].v ) ;
G[T[i].v].push_back( T[i].u+120 ) ;
}
dist[T[i].u][T[i].u+120] += temp[T[i].u] ;
dist[T[i].u+120][T[i].v] += T[i].w ;
}else{
if( vis[T[i].u][T[i].v] == 0 ){
vis[T[i].u][T[i].v] = 1 ;
G[T[i].u].push_back( T[i].v ) ;
G[T[i].v].push_back( T[i].u ) ;
}
dist[T[i].u][T[i].v] += T[i].w ;
}
}
cout << "Case " << caseno++ << ": " << Edmonds_Karp(0,250) << "\n" ;
for( int i = 0 ; i < 300 ; i++ )G[i].clear() ;
}
return 0 ;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZCA7CnZlY3RvcjxpbnQ+R1szMDBdIDsKYm9vbCB2aXNbMzAwXVszMDBdIDsKaW50IGRpc3RbMzAwXVszMDBdIDsKaW50IFBbMzAwXSA7CnN0cnVjdCB0cmlwbGUgewogICAgaW50IHUgLCB2ICwgdyA7CiAgICB0cmlwbGUoKSB7fQogICAgdHJpcGxlKCBpbnQgX3UgLCBpbnQgX3YgLCBpbnQgX3cgKSB7CiAgICAgICAgdSA9IF91IDsKICAgICAgICB2ID0gX3YgOwogICAgICAgIHcgPSBfdyA7CiAgICB9Cn07CmludCBNIDsKaW50IEJhY2tfVHJhY2soaW50IHNyYyxpbnQgc2luaykgewoKICAgIGludCBwYXJlbnQgPSBQW3NpbmtdIDsKICAgIE0gPSBtaW4oIE0gLCBkaXN0W3BhcmVudF1bc2lua10gKTsKCiAgICBpZiggcGFyZW50ID09IHNyYyApewogICAgICAgIGRpc3RbcGFyZW50XVtzaW5rXSAtPSBNIDsKICAgICAgICBkaXN0W3NpbmtdW3BhcmVudF0gKz0gTSA7CiAgICAgICAgcmV0dXJuIE0gOwogICAgfQoKICAgIGludCByZXQgPSBCYWNrX1RyYWNrKCBzcmMgLCBwYXJlbnQgKSA7CgogICAgZGlzdFtwYXJlbnRdW3NpbmtdIC09IHJldCA7CiAgICBkaXN0W3NpbmtdW3BhcmVudF0gKz0gcmV0IDsKCiAgICByZXR1cm4gTSA7Cn0KCmludCBGaW5kX0F1Z19QYXRoKGludCBzcmMsIGludCBzaW5rKSB7CgogICAgbWVtc2V0KCBQICwgMCAsIHNpemVvZiBQICkgOwogICAgcXVldWU8aW50PlEgOwogICAgUS5wdXNoKCBzcmMgKSA7CiAgICBQW3NyY10gPSBzcmMgOwogICAgd2hpbGUoICFRLmVtcHR5KCkgKSB7CiAgICAgICAgaW50IG5TcmMgPSBRLmZyb250KCkgOwogICAgICAgIFEucG9wKCkgOwogICAgICAgIGludCBsID0gR1tuU3JjXS5zaXplKCkgOwogICAgICAgIGZvciggaW50IGkgPSAwIDsgaSA8IGwgOyBpKysgKSB7CiAgICAgICAgICAgIGludCB2ID0gR1tuU3JjXVtpXSA7CiAgICAgICAgICAgIGlmKCBQW3ZdID09IDAgJiYgZGlzdFtuU3JjXVt2XSA+IDAgKSB7CiAgICAgICAgICAgICAgICBQW3ZdID0gblNyYyA7CiAgICAgICAgICAgICAgICBRLnB1c2goIHYgKSA7CiAgICAgICAgICAgICAgICBpZiggdiA9PSBzaW5rICkgewogICAgICAgICAgICAgICAgICAgIE0gPSAxIDw8IDMwIDsKICAgICAgICAgICAgICAgICAgICByZXR1cm4gQmFja19UcmFjayhzcmMsc2luaykgOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CgogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwIDsKCn0KCmludCBFZG1vbmRzX0thcnAoaW50IHNyYyxpbnQgc2luaykgewogICAgaW50IGFucyA9IDAgOwogICAgaW50IHRtcCA9IEZpbmRfQXVnX1BhdGgoIHNyYyAsIHNpbmsgKSA7CiAgICBhbnMgKz0gdG1wIDsKICAgIHdoaWxlKCB0bXAgKSB7CiAgICAgICAgdG1wID0gRmluZF9BdWdfUGF0aCggc3JjICwgc2luayApIDsKICAgICAgICBhbnMgKz0gdG1wIDsKICAgIH0KICAgIHJldHVybiBhbnMgOwp9CgppbnQgbWFpbigpIHsKCiAgICBpbnQgY2FzZXMgLCBjYXNlbm8gPSAxIDsKICAgIHNjYW5mKCIlZCIsJmNhc2VzICkgOwogICAgd2hpbGUoIGNhc2VzIC0tICkgewogICAgICAgIGludCBuIDsKICAgICAgICBzY2FuZigiJWQiLCZuKSA7CiAgICAgICAgaW50IHRlbXBbbisxXSA7CiAgICAgICAgZm9yKCBpbnQgaSA9IDEgOyBpPD0gbiA7IGkrKyApIHsKICAgICAgICAgICAgc2NhbmYoIiVkIiwmdGVtcFtpXSkgOwogICAgICAgIH0KICAgICAgICBpbnQgZSA7CiAgICAgICAgc2NhbmYoIiVkIiwmZSkgOwogICAgICAgIHRyaXBsZSBUW2VdIDsKICAgICAgICBmb3IoIGludCBpID0gMCA7IGkgPCBlIDsgaSsrICkgewogICAgICAgICAgICBpbnQgdSAsIHYgLCB3IDsKICAgICAgICAgICAgc2NhbmYoIiVkJWQlZCIsJnUsJnYsJncpIDsKICAgICAgICAgICAgVFtpXSA9IHRyaXBsZSggdSAsIHYgLCB3ICk7CiAgICAgICAgfQogICAgICAgIGludCBuc3JjICwgbnNpbmsgOwogICAgICAgIHNjYW5mKCIlZCVkIiwmbnNyYywmbnNpbmspIDsKCiAgICAgICAgc2V0PGludD4gU1JDIDsKICAgICAgICBzZXQ8aW50PiBTSU5LIDsKCiAgICAgICAgZm9yKCBpbnQgaSA9IDAgOyBpIDwgbnNyYyA7IGkrKyApIHsKICAgICAgICAgICAgaW50IHRtcCA7CiAgICAgICAgICAgIHNjYW5mKCIlZCIsJnRtcCkgOwogICAgICAgICAgICBTUkMuaW5zZXJ0KHRtcCkgOwogICAgICAgIH0KICAgICAgICBmb3IoIGludCBpID0gMCA7IGkgPCBuc2luayA7IGkrKyApIHsKICAgICAgICAgICAgaW50IHRtcCA7CiAgICAgICAgICAgIHNjYW5mKCIlZCIsJnRtcCkgOwogICAgICAgICAgICBTSU5LLmluc2VydCh0bXApIDsKICAgICAgICB9CgogICAgICAgIG1lbXNldChkaXN0ICwgMCAsIHNpemVvZiBkaXN0ICkgOwogICAgICAgIG1lbXNldCh2aXMgLCAwICwgc2l6ZW9mIHZpcyApIDsKICAgICAgICBmb3IoIHNldDxpbnQ+OjppdGVyYXRvciBpdCA9IFNSQy5iZWdpbigpIDsgaXQgIT0gU1JDLmVuZCgpIDsgaXQrKyApIHsKICAgICAgICAgICAgaWYoIHZpc1swXVsqaXRdID09IDAgKSB7CiAgICAgICAgICAgICAgICBHWzBdLnB1c2hfYmFjayggKml0ICkgOwogICAgICAgICAgICAgICAgdmlzWzBdWyppdF0gPSAxIDsKICAgICAgICAgICAgfQogICAgICAgICAgICBkaXN0WzBdWyppdF0gKz0gdGVtcFsqaXRdIDsKICAgICAgICB9CiAgICAgICAgZm9yKCBzZXQ8aW50Pjo6aXRlcmF0b3IgaXQgPSBTSU5LLmJlZ2luKCkgOyBpdCAhPSBTSU5LLmVuZCgpIDsgaXQrKyApIHsKICAgICAgICAgICAgaWYoIHZpc1sqaXRdWzI1MF0gPT0gMCApIHsKICAgICAgICAgICAgICAgIEdbKml0XS5wdXNoX2JhY2soIDI1MCApIDsKICAgICAgICAgICAgICAgIHZpc1sqaXRdWzI1MF0gPSAxIDsKICAgICAgICAgICAgfQogICAgICAgICAgICBkaXN0WyppdF1bMjUwXSArPSB0ZW1wWyppdF0gOwogICAgICAgIH0KCiAgICAgICAgZm9yKCBpbnQgaSA9IDAgOyBpIDwgZSA7IGkrKyApIHsKICAgICAgICAgICAgaWYoU1JDLmZpbmQoVFtpXS51KT09U1JDLmVuZCgpICkgewogICAgICAgICAgICAgICAgaWYoIHZpc1tUW2ldLnVdW1RbaV0udSsxMjBdID09IDAgKSB7CgogICAgICAgICAgICAgICAgICAgIHZpc1tUW2ldLnVdW1RbaV0udSsxMjBdID0gMSA7CgogICAgICAgICAgICAgICAgICAgIEdbVFtpXS51XS5wdXNoX2JhY2soIFRbaV0udSsxMjApIDsKICAgICAgICAgICAgICAgICAgICBHW1RbaV0udSsxMjBdLnB1c2hfYmFjayggVFtpXS51ICkgOwoKICAgICAgICAgICAgICAgICAgICBHW1RbaV0udSsxMjBdLnB1c2hfYmFjayggVFtpXS52ICkgOwogICAgICAgICAgICAgICAgICAgIEdbVFtpXS52XS5wdXNoX2JhY2soIFRbaV0udSsxMjAgKSA7CgoKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGRpc3RbVFtpXS51XVtUW2ldLnUrMTIwXSArPSB0ZW1wW1RbaV0udV0gOwogICAgICAgICAgICAgICAgZGlzdFtUW2ldLnUrMTIwXVtUW2ldLnZdICs9IFRbaV0udyA7CiAgICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgICAgaWYoIHZpc1tUW2ldLnVdW1RbaV0udl0gPT0gMCApewogICAgICAgICAgICAgICAgICAgIHZpc1tUW2ldLnVdW1RbaV0udl0gPSAxIDsKICAgICAgICAgICAgICAgICAgICBHW1RbaV0udV0ucHVzaF9iYWNrKCBUW2ldLnYgKSA7CiAgICAgICAgICAgICAgICAgICAgR1tUW2ldLnZdLnB1c2hfYmFjayggVFtpXS51ICkgOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZGlzdFtUW2ldLnVdW1RbaV0udl0gKz0gVFtpXS53IDsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgY291dCA8PCAiQ2FzZSAiIDw8IGNhc2VubysrIDw8ICI6ICIgPDwgRWRtb25kc19LYXJwKDAsMjUwKSA8PCAiXG4iIDsKICAgICAgICBmb3IoIGludCBpID0gMCA7IGkgPCAzMDAgOyBpKysgKUdbaV0uY2xlYXIoKSA7CiAgICB9CiAgICByZXR1cm4gMCA7Cn0K