import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
seq = [int(x) for x in input().split()]
d = {}
s = 0
for val in seq:
    try:
        d[val] += 1
    except:
        d[val] = 1
    s += val
for _ in range(int(input())):
    b,c = (int(x) for x in input().split())
    if b in d:
        s -= b * d[b]
        s += c * d[b]
        print(s)
        try:
            d[c] += d[b]
        except:
            d[c] = d[b]
        d[b] = 0
    else:
        print(s)
