n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    b_temp, c_temp = map(int, input().split())
    b.append(b_temp)
    c.append(c_temp)
for j in range(q):

    check_list = [i for i, x in enumerate(a) if x == b[j]]
    if check_list:
        for k in check_list:
            a[k] = c[j]
    print(sum(a))