#!/usr/bin/env python3

# input
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [-1 for _ in range(q)]
c = [-1 for _ in range(q)]
for i in range(q):
    b[i], c[i] = map(int, input().split())

def innerproduct(d):
    ans = 0
    for key, value in d.items():
        ans += int(key)*int(value)
    return ans

# calc
d = {}
for i in a:
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1

# print(d)
ans = sum(a)
for i in range(q):
    if b[i] in d:
        # ans -= b[i]*d[b[i]]
        if c[i] not in d:
            d[c[i]] = d[b[i]]
        else:
            d[c[i]] += d[b[i]]
        # tmp = d[b[i]]
        d[b[i]] = 0
        # ans += tmp*d[c[i]]

    #print(d)
    print(innerproduct(d))