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

for i in range(q):
    for j in range(n):
        if a[j] == s[i][0]:
           a[j] = s[i][1]
    print(sum(a))

  