Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = {}
ans = []
for e in a:
    l[e] = l[e] + 1 if l.get(e) else 1

for _ in range(q):
    b, c = map(int, input().split())
    if b in l:
        l[c] = l[c] + l[b] if l.get(c) else l[b]
        del l[b]
    sum = 0
    for k, v in l.items():
        sum += k * v
    ans.append(sum)

for sum in ans:
    print(sum)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = [0] * 100001
for i in a:
    l[i] += 1

s = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = {}
ans = []
for e in a:
    l[e] = l[e] + 1 if l.get(e) else 1

for _ in range(q):
    b, c = map(int, input().split())
    if b in l:
        l[c] = l[c] + l[b] if l.get(c) else l[b]
        del l[b]
    sum = 0
    for k, v in l.items():
        sum += k * v
    ans.append(sum)

for sum in ans:
    print(sum)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = [0] * 100001
for i in a:
    l[i] += 1

s = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = {}
ans = []
for e in a:
    l[e] = l[e] + 1 if l.get(e) else 1

for _ in range(q):
    b, c = map(int, input().split())
    l[c] = l[c] + l[b] if l.get(c) else l[b]
    del l[b]
    sum = 0
    for k, v in l.items():
        sum += k * v
    ans.append(sum)

for sum in ans:
    print(sum)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = [0] * 100001
for i in a:
    l[i] += 1

s = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = [0] * (10 ** 5 + 1)
ans = []
for e in a:
    l[e] += 1

for _ in range(q):
    b, c = map(int, input().split())
    l[c] += l[b]
    l[b] = 0
    sum = 0
    for i, e in enumerate(l):
        sum += i * e
    ans.append(sum)

for sum in ans:
    print(sum)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = [0] * 100001
for i in a:
    l[i] += 1

s = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = []

for _ in range(q):
    b, c = map(int, input().split())
    if b not in a:
        l.append(sum(a))
        continue
    a = [c if e == b else e for e in a]
    l.append(sum(a))

for a in l:
    print(a)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = [0] * 100001
for i in a:
    l[i] += 1

s = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = []

for _ in range(q):
    b, c = map(int, input().split())
    if b not in a:
        l.append(a)
        continue
    a = [c if e == b else e for e in a]
    l.append(a)

for a in l:
    print(sum(a))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = [0] * 100001
for i in a:
    l[i] += 1

s = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = []

for _ in range(q):
    b, c = map(int, input().split())
    a = [c if e == b else e for e in a]
    l.append(a)

for a in l:
    print(sum(a))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())

l = [0] * 100001
for i in a:
    l[i] += 1

s = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)