def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
    
n=int(input())
A = list(map(int, input().split()))

Q=int(input())
for i in range(Q):
    b, c = map(int, input().split())
    flag=my_index(A,b)
    while flag is not False:
        A[flag]=c
        flag=my_index(A,b)
    print(sum(A))