import numpy as np
import math
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [list(map(int, input().split())) for _ in range(Q)]
def change(A, B, C):
    l = my_index_multi(A, B)
    for i in l:
        A[i] = C
    return A
    
def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


for i in range(0, Q):
    if B[i][0] in A:
        A = change(A, B[i][0], B[i][1])
        print(sum(A))
    else:
        print(sum(A))