_ = int(input().rstrip().split()[0])
a = [int(x) for x in input().rstrip().split()]
_ = int(input().rstrip().split()[0])

try:
    while True:

        l = input().rstrip()
        b, c = l.split(' ')

        for x in range(0, len(a)):
            if a[x] == int(b):
                a[x] = int( c )

        print(sum(a))
except EOFError:
    pass


