Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    a[b] = 0
    #print(sum([x*y for x, y in a.items()]))
    print(sum(a.elements()))

Fixed submission:
from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
a_list = list(map(int, input().split()))
Q = int(input())

a = Counter(a_list)
for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    a[b] = 0
    print(sum([x*y for x, y in a.items()]))
    #print(sum(a.elements()))

Fixed submission:
from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
a_list = list(map(int, input().split()))
Q = int(input())

a = Counter(a_list)
for i in range(Q):
    b, c = map(int, input().split())
    tmp = a[b]
    a[b] = 0
    a[c] += tmp
    print(sum(a.elements()))

Fixed submission:
from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
a_list = list(map(int, input().split()))
Q = int(input())

a = Counter(a_list)
for i in range(Q):
    b, c = map(int, input().split())
    tmp = a[b]
    a[b] = 0
    a[c] += tmp
    print(sum(a.elements()))

Fixed submission:
from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a_list = list(map(int, input().split()))
Q = int(input())

r = [0] * (10**5)

for a in a_list:
    r[a-1] += a

for i in range(Q):
    b, c = map(int, input().split())
    tmp = r[b-1] // b
    r[b-1] = 0
    r[c-1] += tmp * c
    print(sum(r))

Fixed submission:
from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a_list = list(map(int, input().split()))
Q = int(input())

r = [0] * (10^5)
for a in a_list:
    r[a-1] += a

for i in range(Q):
    b, c = map(int, input().split())
    tmp = r[b-1] // b
    r[b-1] = 0
    r[c-1] += tmp * c
    print(sum(r))

Fixed submission:
from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
a = np.asarray(list(map(int, input().split())))
Q = int(input())

for i in range(Q):
    b, c = map(int, input().split())
    a[a == b] = c
    print(np.sum(a))

Fixed submission:
from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
a = np.array(list(map(int, input().split())))
Q = int(input())
bc = [list(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    b, c = bc[i]
    a[a == b] = c
    print(np.sum(a))

Fixed submission:
from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
a = np.array(list(map(int, input().split())))
Q = int(input())
bc = [list(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    b, c = bc[i]
    a[a == b] = c
    print(np.sum(a))

Fixed submission:
from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)