#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; using ll=long long; void IO(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); } string f(ll n){ string res; while(n){ ll r=n%2; n/=2; res+=r+'0'; } reverse(res.begin(),res.end()); if(res.size()==0){ res+='0'; } return res; } int main(){ IO(); ll n,m; cin>>n>>m; vector a(m),b(m); for(ll i=0;i>a[i]>>b[i]; a[i]--; b[i]--; } vector c(n); for(ll i=0;i>c[i]; c[i]--; } vector w(10); for(ll i=0;i<10;i++){ cin>>w[i]; } ll q; cin>>q; vector u(q),v(q); for(ll i=0;i>u[i]>>v[i]; u[i]--; v[i]--; } vector ans(q,1e18); for(ll bit=0;bit<(1<<10);bit++){ ll cost=0; for(ll i=0;i<10;i++){ if(bit&(1<