import sys input = sys.stdin.readline N,M=map(int,input().split()) EDGE=[] for i in range(M): a,b=map(int,input().split()) a-=1 b-=1 EDGE.append((a,b)) C=list(map(int,input().split())) for i in range(N): C[i]-=1 W=list(map(int,input().split())) Q=int(input()) Queries=[] for i in range(Q): a,b=map(int,input().split()) a-=1 b-=1 Queries.append((a,b)) # UnionFind def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) ANS=[1<<62]*Q for i in range(1<=(1<<60): print(-1) else: print(ANS[j])