n = int(input())
A = [int(i) for i in input().split()]

q = int(input())
BC = [[int(i) for i in input().split()] for _ in range(q)]
frag = False

for i in range(q) :
    A.sort()
    frag = False
    b = BC[i][0]
    c = BC[i][1]
    for j in range(q) :
        if A[j] == b :
            frag = True
            A[j] = c
        elif (frag and A[j] != b) or j == q :
            print(sum(A))
            break