n = int(input())
a = list(map(int, input().split()))
q = int(input())
result = []
for i in range(q):
    b = list(map(int, input().split()))
    for k in range(n):
        if a[k] == b[0]:
            a[k] = b[1]
    print(sum(a))