n = int(input())

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

q = int(input())

for i in range(q):
    
    b,c = map(int, input().split())
    
    for i in range(len(a)):
        if a[i] == b:
            a[i] = c

    print(sum(a))
