n = int(input())

l = list(map(int, input().split()))

l.sort()

m = int(input())

for i in range(m):
    a,b = map(int, input().split())
    
    l = [b if j == a else j for j in l]

    print(sum(l))