# coding: utf-8

N = int(input())
A = list(map(int, input().split()))

Q = int(input())

B = []
C = []
for i in range(Q):
    tmp_b, tmp_c = list(map(int, input().split()))

    B.append(tmp_b)
    C.append(tmp_c)

## -- input -- ##

## -- process -- ##

for b, c in zip(B, C):
    A = [c if a == b else a for a in A] 
    print(sum(A))
