N = int(input())

A = list(map(int, input().split()))

total = sum(A)

from collections import defaultdict

d = defaultdict(lambda: 0)

for a in A:

    d[a] += 1

Q = int(input())

ans = []

for i in range(Q):

    x,y = map(int, input().split())

    total += y*d[x]-x*d[x]

    d[y] += d[x]

    d[x] = 0

    ans.append(total)

print(*ans, sep='\n')



from collections import Counter

def solve():

  N = int(input())

  A = list(map(int, input().split()))

  c = Counter(A)

  Q = int(input())

  ans = [0]*Q

  total = sum(A)

  for i in range(Q):

    x,y = map(int, input().split())

    total += c[x]*(y-x)

    c[y] += c[x]

    c[x] = 0

    ans[i] = total

  return ans

print(*solve(),sep='\n')

N = int(input())
A = list(map(int, input().split()))
total = sum(A)
from collections import defaultdict

d = defaultdict(lambda: 0)
for a in A:
    d[a] += 1
Q = int(input())
ans = []
for i in range(Q):
    x, y = map(int, input().split())
    total += y * d[x] - x * d[x]
    d[y] += d[x]
    d[x] = 0
    ans.append(total)
print(*ans, sep="\n")

from collections import Counter


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    Q = int(input())
    ans = [0] * Q
    total = sum(A)
    for i in range(Q):
        x, y = map(int, input().split())
        total += c[x] * (y - x)
        c[y] += c[x]
        c[x] = 0
        ans[i] = total
    return ans


print(*solve(), sep="\n")

-N = int(input()) -A = list(map(int, input().split())) -total = sum(A) -from collections import defaultdict +from collections import Counter -d = defaultdict(lambda: 0) -for a in A: -    d[a] += 1 -Q = int(input()) -ans = [] -for i in range(Q): -    x, y = map(int, input().split()) -    total += y * d[x] - x * d[x] -    d[y] += d[x] -    d[x] = 0 -    ans.append(total) -print(*ans, sep="\n") + +def solve(): +    N = int(input()) +    A = list(map(int, input().split())) +    c = Counter(A) +    Q = int(input()) +    ans = [0] * Q +    total = sum(A) +    for i in range(Q): +        x, y = map(int, input().split()) +        total += c[x] * (y - x) +        c[y] += c[x] +        c[x] = 0 +        ans[i] = total +    return ans + + +print(*solve(), sep="\n")