#include using namespace std; #define int long long #define app push_back #define all(x) (x).begin(),(x).end() #ifdef LOCAL #define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__) #else #define debug(...) #endif #ifdef LOCAL #define __int128 long long #endif // LOCAL const int inf=1e18; const int maxn=1e5+5; int c[maxn];int w[10]; int res[maxn]; int par[maxn]; int get(int x) { if(par[x]==(-1)) return x; int ans=get(par[x]);par[x]=ans;return ans; } void merg(int x,int y) { x=get(x);y=get(y);if(x!=y) par[x]=y; } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n,m;cin>>n>>m; vector > b; for(int i=0;i>x>>y;--x;--y;b.app({x,y});} for(int i=0;i>c[i];--c[i];} for(int i=0;i<10;++i) cin>>w[i]; int q;cin>>q;vector > v; for(int cyc=0;cyc>x>>y;--x;--y;v.app({x,y});} fill(res,res+q,inf); for(int mask=0;mask<(1<<10);++mask) { fill(par,par+maxn,-1);int c1=0; for(int i=0;i<10;++i) {if(mask & (1<