n = int(input())
lista = list(map(int, input().split()))
q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    if b in lista:
        lista = [c if _ == b else _ for _ in lista]
        print(sum(lista))
    else:
        print(sum(lista))
