import collections

N=int(eval(input()))

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

s=sum(A)

Q=int(eval(input()))

d=collections.Counter(A)

for i in range(Q):

  B,C=list(map(int,input().split()))

  s += d[B]*C - d[B]*B

  print(s)

  if C in d:

    d[C]+=d[B]

  else:

    d[C]=d[B]

  d[B]=0
N=int(eval(input()))

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

s=sum(A)

Q=int(eval(input()))

d=[0]*(10**5 +1)#各数字の個数

for i in A:

  d[i]+=1



for i in range(Q):

  B,C=list(map(int,input().split()))

  s += (C-B)*d[B]

  print(s)

  d[C]+=d[B]

  d[B]=0
import collections

N = int(eval(input()))
A = list(map(int, input().split()))
s = sum(A)
Q = int(eval(input()))
d = collections.Counter(A)
for i in range(Q):
    B, C = list(map(int, input().split()))
    s += d[B] * C - d[B] * B
    print(s)
    if C in d:
        d[C] += d[B]
    else:
        d[C] = d[B]
    d[B] = 0

N = int(eval(input()))
A = list(map(int, input().split()))
s = sum(A)
Q = int(eval(input()))
d = [0] * (10**5 + 1)  # 各数字の個数
for i in A:
    d[i] += 1
for i in range(Q):
    B, C = list(map(int, input().split()))
    s += (C - B) * d[B]
    print(s)
    d[C] += d[B]
    d[B] = 0

-import collections - -d = collections.Counter(A) +d = [0] * (10**5 + 1)  # 各数字の個数 +for i in A: +    d[i] += 1 -    s += d[B] * C - d[B] * B +    s += (C - B) * d[B] -    if C in d: -        d[C] += d[B] -    else: -        d[C] = d[B] +    d[C] += d[B]