n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    bi,ci = map(int, input().split())
    b.append(bi)
    c.append(ci)
for i in range(q):
    for j in range(n):
        if a[j] == b[i]:
            a[j] = c[i]
    print(sum(a))