N=int(input())
A=list(map(int, input().split()))
Q=int(input())
D=sum(A)
for i in range(Q):
    count=0
    B,C=map(int,input().split())
    for j in range(N):
        if A[j]==B:
            A[j]=C
            count+=1
    if B<=C:
      D=D+(C-B)*count
      print(D)
    if B>C:
      D=D+(C-B)*count
      print(D)