from collections import Counter



R = lambda: list(map(int, input().split()))

R()

d = Counter(R())

s = sum(d.elements())

q, = R()

for _ in range(q):

  b, c = R()

  s += (c - b) * d[b]

  print(s)

  d[c]+=d[b]

  d[b] = 0

R = lambda: list(map(int, input().split()))

R()

a = [0] * 100001

s = 0

for x in R():

  s += x

  a[x] += 1

q, = R()

for _ in range(q):

  b, c = R()

  s += (c - b) * a[b]

  print(s)

  a[c]+=a[b]

  a[b] = 0

from collections import Counter

R = lambda: list(map(int, input().split()))
R()
d = Counter(R())
s = sum(d.elements())
(q,) = R()
for _ in range(q):
    b, c = R()
    s += (c - b) * d[b]
    print(s)
    d[c] += d[b]
    d[b] = 0

R = lambda: list(map(int, input().split()))
R()
a = [0] * 100001
s = 0
for x in R():
    s += x
    a[x] += 1
(q,) = R()
for _ in range(q):
    b, c = R()
    s += (c - b) * a[b]
    print(s)
    a[c] += a[b]
    a[b] = 0

-from collections import Counter - -d = Counter(R()) -s = sum(d.elements()) +a = [0] * 100001 +s = 0 +for x in R(): +    s += x +    a[x] += 1 -    s += (c - b) * d[b] +    s += (c - b) * a[b] -    d[c] += d[b] -    d[b] = 0 +    a[c] += a[b] +    a[b] = 0