import numpy as np

N=int(eval(input()))

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

SUM=sum(A)

Q=int(eval(input()))

List=np.array([0 for _ in range(10**5+1)])

for a in A:

    List[a]+=1

for q in range(Q):

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

    SUM-=B*List[B]

    SUM+=C*List[B]

    List[C]+=List[B]

    List[B]=0

    print(SUM)
N=int(eval(input()))

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

SUM=sum(A)

Q=int(eval(input()))

List=[0 for _ in range(10**5+1)]

for a in A:

    List[a]+=1

for q in range(Q):

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

    SUM-=B*List[B]

    SUM+=C*List[B]

    List[C]+=List[B]

    List[B]=0

    print(SUM)
import numpy as np

N = int(eval(input()))
A = list(map(int, input().split()))
SUM = sum(A)
Q = int(eval(input()))
List = np.array([0 for _ in range(10**5 + 1)])
for a in A:
    List[a] += 1
for q in range(Q):
    B, C = list(map(int, input().split()))
    SUM -= B * List[B]
    SUM += C * List[B]
    List[C] += List[B]
    List[B] = 0
    print(SUM)

N = int(eval(input()))
A = list(map(int, input().split()))
SUM = sum(A)
Q = int(eval(input()))
List = [0 for _ in range(10**5 + 1)]
for a in A:
    List[a] += 1
for q in range(Q):
    B, C = list(map(int, input().split()))
    SUM -= B * List[B]
    SUM += C * List[B]
    List[C] += List[B]
    List[B] = 0
    print(SUM)

-import numpy as np - -List = np.array([0 for _ in range(10**5 + 1)]) +List = [0 for _ in range(10**5 + 1)]