using namespace std;

int main()

{

int a[8],sum=0;

for(int j=0;j<8;j++){

cin>>a[j];

sum=sum+a[j];

}

int n;cin>>n;

int p=0;

for(int i=0;i<n;i++){

int x,y;cin>>x>>y;

if(x>0 && y>0){

if(a[x-1]>=a[y-1]){p=p+a[y-1];}

else{p=p+a[x-1];}

}

}

cout<<sum-p<<endl;

```
return 0;
```

}