n = int(input())
a = list(map(int,input().split()))
q = int(input())
a_sum = sum(a)

for i in range(q):
    b,c = map(int,input().split())
    co = 0
    for j in range(n):
        co = co + (a[j]==b)
        a[j] = c*(a[j]==b)+a[j]*(a[j]!=b)
    a_sum = a_sum - b*co + c*co
    print(a_sum)