import sys
import math

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B = [list(map(int,input().split())) for b in range(Q)]

s = 0
S = []

for b in B:
    for n in range(N):
        if A[n] == b[0]:
            A[n] = b[1]

    for a in A:
        s += a

    print(s)
    S.append(s)
    s = 0