N = raw_input()
ns = raw_input()
ns = ns.split(' ')

data = {}
for i in ns:
    i = int(i)
    if i in data:
        data[i] += 1
    else:
        data[i] = 1

Q = raw_input()
opr = []
for _ in range(int(Q)):
    tmp = raw_input()
    tmp = tmp.split(' ')
    opr.append([int(tmp[0]), int(tmp[1])])

ans = 0
for op in opr:
    if op[0] not in data:
        print ans
        continue
    ans = 0
    old = data[op[0]]
    del data[op[0]]
    old2 = 0
    if op[1] in data:
        old2 = data[op[1]]
    data[op[1]] = old + old2
    for k, v in data.iteritems():
        ans += k * v
    print ans

