N = int(input())

AAA = list(map(int, input().split()))

Q = int(input())

for i in range(0, Q):
    BC = list(map(int, input().split()))
    B = BC[0]
    C = BC[1]
    AAA = [C if m == B else m for m in AAA]
    print(sum(AAA))