FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]

####

from collections import defaultdict as ddic

def solve(N, A, Q, queries):
    count = ddic(int)
    for x in A:
        count[x] += 1
    S = sum(A)
    for b, c in queries:
        ct = count[b]
        count[b] = 0
        count[c] += ct
        S += (c-b) * ct
        print S
        

N = rri()
A=rrm()
Q= rri()
queries = [rrm() for _ in xrange(Q)]
solve(N, A, Q, queries)
