n = int(input())
A = list(map(int, input().split()))
q = int(input())
B,C = [], []

for _ in range(q):
    b, c = list(map(int, input().split()))
    B.append(b)
    C.append(c)


for b, c in zip(B,C):
    ans = 0
    for i, a in enumerate(A):
        if a == b:
            ans += c
            A[i] = c
        else:
            ans += a
    print(ans)
