n = int(input())
arr = list(map(int,input().split()))
t = int(input())
su = 0
while t:
    t-=1
    k,r = map(int,input().split())
    p = arr.count(k)
    su = sum(arr)-sum([k]*p)+sum([r]*p)
    arr = list(filter((k).__ne__, arr))
    arr.extend([r]*p)
    print(su)