n = int(input())
a = list(input().split())
q = int(input())
b = list(input().split() for i in range(q))

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