n = int(eval(input()))

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

q = int(eval(input()))

total = sum(A)



l = [[i, 0] for i in range(10**5+1)]

for _ in range(n):

    l[A[_]][1] += 1



for i in range(q):

    b, c = list(map(int,input().split()))

    total -= (l[b][0] * l[b][1])

    total += (l[c][0] * l[b][1])

    print(total)

    l[c][1] += l[b][1]

    l[b][1] = 0
n = int(eval(input()))

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

q = int(eval(input()))

total = sum(A)



l = [0 for i in range(10**5+1)]

for _ in range(n):

    l[A[_]] += 1



for i in range(q):

    b, c = list(map(int,input().split()))

    total += (c * l[b])

    total -= (b * l[b])

    print(total)

    l[c] += l[b]

    l[b] = 0

n = int(eval(input()))
A = list(map(int, input().split()))
q = int(eval(input()))
total = sum(A)
l = [[i, 0] for i in range(10**5 + 1)]
for _ in range(n):
    l[A[_]][1] += 1
for i in range(q):
    b, c = list(map(int, input().split()))
    total -= l[b][0] * l[b][1]
    total += l[c][0] * l[b][1]
    print(total)
    l[c][1] += l[b][1]
    l[b][1] = 0

n = int(eval(input()))
A = list(map(int, input().split()))
q = int(eval(input()))
total = sum(A)
l = [0 for i in range(10**5 + 1)]
for _ in range(n):
    l[A[_]] += 1
for i in range(q):
    b, c = list(map(int, input().split()))
    total += c * l[b]
    total -= b * l[b]
    print(total)
    l[c] += l[b]
    l[b] = 0

-l = [[i, 0] for i in range(10**5 + 1)] +l = [0 for i in range(10**5 + 1)] -    l[A[_]][1] += 1 +    l[A[_]] += 1 -    total -= l[b][0] * l[b][1] -    total += l[c][0] * l[b][1] +    total += c * l[b] +    total -= b * l[b] -    l[c][1] += l[b][1] -    l[b][1] = 0 +    l[c] += l[b] +    l[b] = 0