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

while True:
    try:
        bc=list(map(int,input().split()))
        b = bc[0]
        c = bc[1]

        a = [c if i == b else i for i in a]
        print(sum(a))
    except:
        break;