n = int(input())
a = list(map(int, input().split()))
q = int(input())
xy = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*xy)]

sum = 0

for cnt_q in range(q):
    sum = 0
    for cnt_n in range(n):
        if a[cnt_n] == b[cnt_q]:
            a[cnt_n] = c[cnt_q]
    for num in range(n):
        sum += a[num]
    print(sum)
