n = int(input())

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

m = int(input())

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