a = int(input())
sequence = list(map(int, input().split(" ")))
q = int(input())
dictionary = {}
for i in range(q):
    pair = list(map(int, input().split(" ")))
    dictionary[pair[0]] = pair[1]

for key in dictionary:
    Sum = 0
    for n in range(len(sequence)):
        if key==sequence[n]:
            sequence[n]=dictionary[key]          
    print(sum(sequence))

    