n = int(input())
a = list(map(int, input().split()))
q = int(input())
b_c = []
for i in range(q):
    b_c.append(list(input().split()))

for i in range(q):
    for k in range(n):
        if int(b_c[i][0]) == a[k]:
            a[k] = int(b_c[i][1])
    print(sum(a))