import collections
FAST_IO = 1
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())
 
    
    

N = rri()
arr = rrm()
dic = collections.Counter(arr)
s = sum(arr)
q = rri()
for _ in range(q):
    a, b= rrm()
    s+=dic[a]*(b-a)
    dic[b]+=dic[a]
    del dic[a]
    print(s)