class UF: def __init__(self,n): self.p = [-1]*n def f(self,x): if self.p[x]<0: return x else: self.p[x] = self.f(self.p[x]); return self.p[x] def u(self,x,y): x = self.f(x); y = self.f(y) if x==y: return if -self.p[x]<-self.p[y]: x,y = y,x self.p[x] += self.p[y]; self.p[y] = x def s(self,x,y): return self.f(x) == self.f(y) n,m = map(int,input().split()) ab = [[v-1 for v in map(int,input().split())] for _ in range(m)] c = [v-1 for v in map(int,input().split())] w = list(map(int,input().split())) q = int(input()); k = 10; d = [sum(w)+1]*q uv = [[v-1 for v in map(int,input().split())] for _ in range(q)] for s in range(1<>i&1: x += v for a,b in ab: if s>>c[a]&1 and s>>c[b]&1: uf.u(a,b) for i,(u,v) in enumerate(uv): if uf.s(u,v): d[i] = min(d[i],x) for v in d: print(v if v<=sum(w) else -1)