N = int(eval(input()))

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

B = [0]*(N+1)

for n in range(N):

    B[n+1] = B[n] + A[n]

C = B.pop()



Z = {}

for n in range(N):

    Z[A[n]] = 0

for n in range(N):

    Z[A[n]] += 1



D = []

Q = int(eval(input()))

for q in range(Q):

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

    if x in Z:

        C = C - x*Z[x]

        C = C + y*Z[x]

        D.append(C)

        if x == y:

            continue

        if y in Z:

            Z[y] += 1*Z[x]

        else:

            Z[y] = Z[x]

        Z.pop(x)

    else:

        D.append(C)

for d in D:

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

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

C = sum(A)

Z = {}

for n in range(N):

    Z[A[n]] = 0

for n in range(N):

    Z[A[n]] += 1

D = []

Q = int(eval(input()))

for q in range(Q):

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

    if x in Z:

        C = C - x*Z[x]

        C = C + y*Z[x]

        D.append(C)

        if x == y:

            continue

        if y in Z:

            Z[y] += 1*Z[x]

        else:

            Z[y] = Z[x]

        Z.pop(x)

    else:

        D.append(C)

for d in D:

    print(d)

N = int(eval(input()))
A = list(map(int, input().split()))
B = [0] * (N + 1)
for n in range(N):
    B[n + 1] = B[n] + A[n]
C = B.pop()
Z = {}
for n in range(N):
    Z[A[n]] = 0
for n in range(N):
    Z[A[n]] += 1
D = []
Q = int(eval(input()))
for q in range(Q):
    x, y = list(map(int, input().split()))
    if x in Z:
        C = C - x * Z[x]
        C = C + y * Z[x]
        D.append(C)
        if x == y:
            continue
        if y in Z:
            Z[y] += 1 * Z[x]
        else:
            Z[y] = Z[x]
        Z.pop(x)
    else:
        D.append(C)
for d in D:
    print(d)

N = int(eval(input()))
A = list(map(int, input().split()))
C = sum(A)
Z = {}
for n in range(N):
    Z[A[n]] = 0
for n in range(N):
    Z[A[n]] += 1
D = []
Q = int(eval(input()))
for q in range(Q):
    x, y = list(map(int, input().split()))
    if x in Z:
        C = C - x * Z[x]
        C = C + y * Z[x]
        D.append(C)
        if x == y:
            continue
        if y in Z:
            Z[y] += 1 * Z[x]
        else:
            Z[y] = Z[x]
        Z.pop(x)
    else:
        D.append(C)
for d in D:
    print(d)

-B = [0] * (N + 1) -for n in range(N): -    B[n + 1] = B[n] + A[n] -C = B.pop() +C = sum(A)