qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
S = list(input())
T = list(input())
print(S, T)
c = 0
for i in range(len(S)):
    if S[i] != T[i]:
        c += 1
print(c)

# Fixed code:
S = list(input())
T = list(input())
c = 0
for i in range(len(S)):
    if S[i] != T[i]:
        c += 1
print(c)
# Buggy code:
S = input()
T = input()
k = len(T)
m = 0
for i in range(k):
  if S[k] == T[k]:
    m = m
  else:
    m += 1
print(m)

# Fixed code:
S = input()
T = input()
k = len(T)
m = 0
for i in range(k):
  if S[i] != T[i]:
    m += 1
print(m)
# Buggy code:
S = input()
T = input()

res = sum(1 if s == t else 0 for s, t in zip(S,T))
print(res)

# Fixed code:
S = input()
T = input()
 
res = sum(0 if s == t else 1 for s, t in zip(S,T))
print(res)
# Buggy code:
S = input()
T = input()

S = list(S)
T = list(T)

i = 0
j = 0

while j < len(S):
  if S[j] = T[j]:
    i = i
    j += 1
  else:
    i += 1
    j += 1
    
print(i)

# Fixed code:
S = input()
T = input()

S = list(S)
T = list(T)

i = 0
j = 0

while j < len(S):
    if S[j] == T[j]:
        i = i
        j += 1
    else:
        i += 1
        j += 1

print(i)
# Buggy code:
s = str(input())
t = str(input())
c = 0
for i in len(s):
  if(s[i] != t[i]):
    c+=1

print(c)

# Fixed code:
s = str(input())
t = str(input())
c = 0
for i in range(len(s)):
  if(s[i] != t[i]):
    c+=1
 
print(c)
# Buggy code:
s,t = input()
if s == t:
  print(0)
count = 0
for i in range(len(s)):
  if s[i] != t[i]:
    count += 1
print(count)
    

# Fixed code:
s = input()
t = input()

count = 0
for i in range(len(s)):
  if s[i] != t[i]:
    count += 1
print(count)
# Buggy code:
m=input()
n=input()
count=0;
for i in range(len(m))
    if m!=n :
         count+=1
print(count)

# Fixed code:
m=input()
n=input()
count=0;
for i in range(len(m)):
    if m[i]!=n[i] :
         count+=1
print(count)
# Buggy code:
a=[input() for i in range(2)]
P=a[0]
S=a[1]
count=0
for t in range(0,len(P)-1):
  if P[t] != S[t]:
    count=count+1
print(count)

# Fixed code:
a=[input() for i in range(2)]
P=a[0]
S=a[1]
count=0
for t in range(len(P)):
  if P[t] != S[t]:
    count=count+1
print(count)
# Buggy code:
a=input()
b=input()
c=0
for i in range(len(a)):
  if a[i]==b[i]:
    c=c+1
print(c)

# Fixed code:
a=input()
b=input()
c=0
for i in range(len(a)):
  if a[i]==b[i]:
    c=c+1
print(len(a)-c)
# Buggy code:
s = input()
t = input()
count=0
for i in len(s):
  if s[i] != t[i]:
    count+=1
print(count)


# Fixed code:
s = input()
t = input()

count = 0
if s != t:
    for i in range(0,len(s)):
        if s[i] != t[i]:
            count += 1

print(count)
# Buggy code:
def calculate(s,t):
  count = 0
  for i in t:
    if i != s[j]:
      count += 1
    j += 1
  return count  


s = raw_input()
t = raw_input()
print(calculate(s,t))

# Fixed code:
def calculate(s,t):
    count = 0
    j = 0
    for i in s:
        if i != t[j]:
            count += 1
        j += 1
    return count
    
s = input()
t = input()
print(calculate(s,t))
# Buggy code:
S = input()
T = input()
W = 0
for i in range(len(S)):
    if S[i] != T[i]:
        w += 1
print(W)

# Fixed code:
S = input()
T = input()
W = 0
for i in range(len(S)):
    if S[i] != T[i]:
        W += 1
print(W)
# Buggy code:
from sys import stdin
input=stdin.readline
input()
a=list(map(int,input().split()))
ans=sum(a)
b=[0]*(max(a)+1)
for i in a:
  b[i]+=1
c=int(input())
for i in range(c):
  n,m=map(int,input().split())
  x=b[n]
  if x>0:
    b[m]+=x
    b[n]=0
    ans+=(m-n)*x
  print(ans)

# Fixed code:
from sys import stdin
input=stdin.readline
input()
a=list(map(int,input().split()))
ans=sum(a)
b=[0]*(10**5+1)
for i in a:
  b[i]+=1
c=int(input())
for i in range(c):
  n,m=map(int,input().split())
  if b[n]>0:
    x=b[n]
    if x>0:
      b[m]+=x
      b[n]=0
      ans+=(m-n)*x
  print(ans)
# Buggy code:
import collections as cl
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

sum = 0
for i in range(N):
    sum += A[i]
dic = cl.Counter(A)
print(A, dic, sum)

l = []
for _ in range(Q):
    b, c = map(int, input().split())
    if dic.get(b) == None:
        continue
    if b < c:
        sum += (c - b) * dic[b]
    else:
        sum -= (b- c) * dic[b]
    l.append(sum)
    if c not in dic:
        dic[c] = dic.pop(b)
    else:
        dic[c] = dic.pop(b) + dic[c]
    print(dic)    


for s in l:
    print(s)

# Fixed code:
import collections as cl
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

sum = 0
for i in range(N):
    sum += A[i]
dic = cl.Counter(A)

l = []
for _ in range(Q):
    b, c = map(int, input().split())
    x = dic.get(b)
    if x == None:
        l.append(sum)
        continue
    if b < c:
        sum += (c - b) * x
    else:
        sum -= (b - c) * x
    l.append(sum)
    if c not in dic:
        dic[c] = dic.pop(b)
    else:
        dic[c] = dic.pop(b) + dic[c]

for s in l:
    print(s)
# Buggy code:
n=int(input())
a=list(map(int, input().split()))
q=int(input())
results=[]

S=sum(a)

table=[0]*(10**6)

for i in range(n):
    table[a[i]]+=1

for i in range(q):
    b, c=map(int, input().split())
    if table[b]!=0:
        cnt=table[b]
        table[c]+=cnt
        ans=S+(cnt*(c-b))
        results.append(ans)
        table[b]=0
        S=ans
    else:
        results.appned(S)

for result in results:
    print(result)

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

S=sum(a)

table=[0]*(10**6)

for i in range(n):
    table[a[i]]+=1

for i in range(q):
    b, c=map(int, input().split())
    if table[b]!=0:
        cnt=table[b]
        table[c]+=cnt
        ans=S+(cnt*(c-b))

        print(ans)

        table[b]=0
        S=ans
    else:
        print(S)
# Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 23 21:04:33 2020

@author: naoki
"""

N = int(input()) # input the row A length "N" 
A = list(map(int,input().split())) # input the row of A 
Q = int(input()) # input the number of trying operation 
BC = [list(map(int,input().split())) for i in range(Q)]
S = 0
num = [0 for i in range(100001)] 
for i in A:
    S += i # Sum of all conponents of the row "A"
    num[i]+=1 

for B,C in BC:
    S = S + (C - B) * num[B+1]
    num[C+1] += num[B+1]
    num[B+1] = 0 
    print(S)



# Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 23 21:04:33 2020

@author: naoki
"""

N = int(input()) # input the row A length "N" 
A = list(map(int,input().split())) # input the row of A 
Q = int(input()) # input the number of trying operation 
BC = [list(map(int,input().split())) for i in range(Q)]
S = 0
num = [0 for i in range(100001)] 
for i in A:
    S += i # Sum of all conponents of the row "A"
    num[i]+=1 

for B,C in BC:
    S = S + (C - B) * num[B]
    num[C] += num[B]
    num[B] = 0 
    print(S)
# Buggy code:
N = input()
arr = [int(x) for x in input().split()]

q = int(input())
ans = sum(arr)

hashmap = {}
for val in arr:
    if val in hashmap:
        hashmap[val] += 1
    else:
        hashmap[val] = 1


while q > 0:
    print(hashmap)
    [x, y] =  [int(x) for x in input().split()]
    if x in hashmap:
        if y in hashmap:
            hashmap[y] += hashmap[x]
            ans -= hashmap[x]*x
            ans += y*hashmap[x]
        else:
            diff = hashmap[x] * x
            ans -= diff
            hashmap[y] = hashmap[x]
            del hashmap[x]
            add = hashmap[y] * y
            ans += add
        
    print('ans', ans)
    q -=1

# Fixed code:
N = input()
arr = [int(x) for x in input().split()]

q = int(input())
ans = sum(arr)

hashmap = {}
for val in arr:
    if val in hashmap:
        hashmap[val] += 1
    else:
        hashmap[val] = 1


while q > 0:

    [x, y] =  [int(x) for x in input().split()]
    if x in hashmap:
        if y in hashmap:
            hashmap[y] += hashmap[x]
            ans -= hashmap[x]*x
            ans += y*hashmap[x]
            del hashmap[x]
        else:
            diff = hashmap[x] * x
            ans -= diff
            hashmap[y] = hashmap[x]
            del hashmap[x]
            add = hashmap[y] * y
            ans += add
        
    print(ans)
    q -=1
# Buggy code:
n = int(input())
alist = [int(s) for s in input().split(" ")]
adict = {}
ans = 0
for a in alist:
  ans += a
  if a in adict:
    adict[a] += 1
  else:
    adict[a] = 1
q = int(input())
bclist = []
for _ in range(q):
  b, c = [int(s) for s in input().split(" ")]
  bclist.append([b, c])

for b, c in bclist:
  if c in adict and b in adict:
    ans += c * (adict[c] + adict[b]) - b * adict[b]
    adict[c] += adict[b]
    del adict[b]
  elif b in adict:
    ans += (c - b) * adict[b]
    adict[c] = adict[b]
    del adict[b]
  print(ans)

# Fixed code:
n = int(input())
alist = [int(s) for s in input().split(" ")]
adict = {}
ans = 0
for a in alist:
  ans += a
  if a in adict:
    adict[a] += 1
  else:
    adict[a] = 1
q = int(input())
bclist = []
for _ in range(q):
  b, c = [int(s) for s in input().split(" ")]
  bclist.append([b, c])

for b, c in bclist:
  if c in adict and b in adict:
    ans += (c - b) * adict[b]
    adict[c] += adict[b]
    del adict[b]
  elif b in adict:
    ans += (c - b) * adict[b]
    adict[c] = adict[b]
    del adict[b]
  print(ans)
# Buggy code:
from collections import Counter
n = int(input())
la = list(map(int, input().split()))
s = sum(la)
d = dict(Counter(la))

q = int(input())
for _ in range(q):
    b,c = map(int, input().split())
    nb = d.pop(b)
    delta = (c-b)*nb
    s += delta
    print(s)
    if c in d:
        d[c] += nb
    else:
        d[c] = nb

# Fixed code:
from collections import Counter
n = int(input())
la = list(map(int, input().split()))
s = sum(la)
d = dict(Counter(la))

q = int(input())
for _ in range(q):
    b,c = map(int, input().split())
    if b in d:
        nb = d.pop(b)
    else:
        nb = 0
    delta = (c-b)*nb
    s += delta
    print(s)
    if nb > 0:
        if c in d:
            d[c] += nb
        else:
            d[c] = nb
# Buggy code:
n=int(input())
a = list(map(int,input().split()))
q=int(input())
bc = [list(map(int, input().split())) for l in range(q)]
cnt=[0]*(n+1)
Sum=0
for i in range(n):
  cnt[a[i]]+=1
  Sum+=a[i]
for i in range(q):
  Sum+=(bc[i][1]-bc[i][0])*cnt[bc[i][1]]                           
  cnt[bc[i][1]]+=cnt[bc[i][0]]
  cnt[bc[i][0]]=0
  print(Sum)

# Fixed code:
n=int(input())
a = list(map(int,input().split()))
q=int(input())
bc = [list(map(int, input().split())) for l in range(q)]
cnt=[0]*100001
Sum=0
for i in range(n):
  cnt[a[i]]+=1
  Sum+=a[i]
for i in range(q):
  Sum+=(bc[i][1]-bc[i][0])*cnt[bc[i][0]]                           
  cnt[bc[i][1]]+=cnt[bc[i][0]]
  cnt[bc[i][0]]=0
  print(Sum)
# Buggy code:
import collections

def calc_sum(c):
    sum_val = 0
    for key, val in c.items():
        sum_val += key * val
    return sum_val

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

actions = []

for i in range(Q):
    B, C = map(int, input().split())
    actions.append({'B':B, 'C':C})

c = collections.Counter(arr)
sum_val = calc_sum(c)

for i in range(Q):
    B = actions[i]['B']
    C = actions[i]['C']
    if B in c:
        c[C] += c[B]
        sum_val += c[C] * C - c[B] * B
        c.pop(B)

    print(sum_val)

# Fixed code:
import collections

def calc_sum(c):
    sum_val = 0
    for key, val in c.items():
        sum_val += key * val
    return sum_val

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

actions = []

for i in range(Q):
    B, C = map(int, input().split())
    actions.append({'B':B, 'C':C})

c = collections.Counter(arr)
sum_val = calc_sum(c)

for i in range(Q):
    B = actions[i]['B']
    C = actions[i]['C']
    if B in c:
        c[C] += c[B]
        sum_val += c[B] * C - c[B] * B
        c.pop(B)

    print(sum_val)
# Buggy code:
n = int(input())
m = {}
tot = 0
for a in map(int,input().split()):
  tot += m
  if a not in m:
    m[a]=0
  m[a] += 1
q = int(input())
for step in range(q):
  b,c = map(int,input().split())
  if c not in m:
    m[c] = 0
  if b in m:
    m[c] += m[b]
    tot += m[b]*(c-b)
    m[b] = 0
  print(tot)



# Fixed code:
n = int(input())
m = {}
tot = 0
for a in map(int,input().split()):
  tot += a
  if a not in m:
    m[a]=0
  m[a] += 1
q = int(input())
for step in range(q):
  b,c = map(int,input().split())
  if c not in m:
    m[c] = 0
  if b in m:
    m[c] += m[b]
    tot += m[b]*(c-b)
    m[b] = 0
  print(tot)
# Buggy code:
from collections import defaultdict
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
arr = defaultdict(int)
for k, v in Counter(a).items():
    arr[k] = v
q = int(input())
bc = []
for _ in range(q):
    b, c = map(int, input().split())
    bc.append((b, c))

whole = sum([x * y for x, y in arr.items()])

for b, c in bc:
    whole += c * arr[c] - b * arr[b]
    print(whole)
    arr[c] += arr[b]
    arr[b] = 0

# Fixed code:
from collections import defaultdict
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
arr = defaultdict(int)
for k, v in Counter(a).items():
    arr[k] = v
q = int(input())
bc = []
for _ in range(q):
    b, c = map(int, input().split())
    bc.append((b, c))

whole = sum([x * y for x, y in arr.items()])

for b, c in bc:
    arr[c] += arr[b]
    tmp = arr[b]
    arr[b] = 0
    whole += (c - b) * tmp
    print(whole)
# Buggy code:
from collections import defaultdict
N = int(input())
raw_numbers = list(map(int, input().split()))
numbers = defaultdict(int)

for num in raw_numbers:
    numbers[num] += 1
    
total = sum(raw_numbers)
    
Q = int(input())

for _ in range(Q):
    a, b = list(map(int, input().split()))
    numbers[b] += numbers[a]
    total -= a * numbers[a]
    total += b * (numbers[b] - numbers[a])
    numbers[a] = 0
    print(total)

# Fixed code:
from collections import defaultdict
 
N = int(input())
raw_numbers = list(map(int, input().split()))
Q = int(input())
 
total = sum(raw_numbers)
 
numbers = defaultdict(int)
 
for num in raw_numbers:
    numbers[num] += 1

for i in range(Q):
    a, b = map(int, input().split())
    taken = numbers[a]
    total -= numbers[a]*a
    numbers[b] += numbers[a]
    numbers[a] = 0
    total += taken*b
    print(total)
# Buggy code:
N = int(input())

An = list(map(int, input().split()))
Q = int(input())

L = [0] * 100001
for item in An:
    L[item] += 1

sum = sum(An)

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

# Fixed code:
N = int(input())

An = list(map(int, input().split()))
Q = int(input())

L = [0] * 100001
for item in An:
    L[item] += 1

sum = sum(An)

for i in range(Q):
    b, c = map(int, input().split())
    sum += (c-b) * L[b]
    L[c] += L[b]
    L[b] = 0
    print(sum)
# Buggy code:
from collections import Counter

n = input()
N = int(n)
A = [int(a) for a in input().split()]
q = input()
Q = int(q)
B, C = [], []
for i in range(Q):
    b, c = input().split()
    B.append(int(b))
    C.append(int(c))


my_dict = Counter(A)

def cals_sum(my_dict):
    values = [ my_dict[key]*key for key in my_dict.keys() if my_dict[key] != 0]
    #for key in my_dict.keys():
    #    value = my_dict[key]
    #    sum += int(key) * int(value)
    return sum(values)
  
my_sum = cals_sum(my_dict)

for i in range(len(B)):
    b = B[i]
    c = C[i]
    tmpb = my_dict[b] 
    my_dict[b] = 0
    tmpc = my_dict[c]
    my_dict[c] = tmpb + tmpc
    
    my_sum += ((tmpb + tmpc)*c - tmpb*b)

    print(my_sum)


# Fixed code:
from collections import Counter

n = input()
N = int(n)
A = [int(a) for a in input().split()]
q = input()
Q = int(q)
B, C = [], []
for i in range(Q):
    b, c = input().split()
    B.append(int(b))
    C.append(int(c))


my_dict = Counter(A)

def cals_sum(my_dict):
    values = [ my_dict[key]*key for key in my_dict.keys() if my_dict[key] != 0]
    #for key in my_dict.keys():
    #    value = my_dict[key]
    #    sum += int(key) * int(value)
    return sum(values)
  
my_sum = cals_sum(my_dict)

for i in range(len(B)):
    b = B[i]
    c = C[i]
    tmpb = my_dict[b] 
    my_dict[b] = 0
    tmpc = my_dict[c]
    my_dict[c] = tmpb + tmpc
    
    my_sum += ((tmpb)*c - tmpb*b)

    print(my_sum)
# Buggy code:
from collections import Counter
n = int(input())
ls = list(map(int, input().split()))
q = int(input())
count = Counter(ls)
sm = sum(ls)

for _ in range(q):
    b, q = map(int, input().split())
    if b in count:
        sm -= count[b] * b
        sm += count[b] * q
        print(sm)
    if q in count:
        count[q] += count[b]

        count[b] = 0
    else:
        count[q] = count[b]

        count[b] = 0


# Fixed code:
from collections import Counter
n = int(input())
ls = list(map(int, input().split()))
q = int(input())
count = Counter(ls)
sm = sum(ls)

for _ in range(q):
    b, q = map(int, input().split())
    if b in count:
        sm -= count[b] * b
        sm += count[b] * q
        print(sm)
    else:
        print(sm)
    if q in count:
        count[q] += count[b]

        count[b] = 0
    else:
        count[q] = count[b]

        count[b] = 0
# Buggy code:


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
nizi = [0] * (max(A)+1)
for i in range(len(A)):
    # print(A[i], A)
    nizi[A[i]] += 1
sumall = sum(A)
for q in range(Q):
    B, C = map(int, input().split())
    sumall += (C-B) * nizi[B]
    nizi[C] =+ nizi[B]
    nizi[B] = 0
    print(sumall)

# Fixed code:


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
nizi = [0] * (10**5+1)
for i in range(len(A)):
    # print(A[i], A)
    nizi[A[i]] += 1
sumall = sum(A)
for q in range(Q):
    # print(nizi)
    B, C = map(int, input().split())
    sumall += (C-B) * nizi[B]
    nizi[C] += nizi[B]
    nizi[B] = 0
    print(sumall)
# Buggy code:
from collections import Counter
import numpy as np
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)
A = Counter(A)
bc = [tuple(map(int, input().split())) for i in range(Q)]
for b, c in bc:
    v = A.pop(b, None)
    if v:
        A[c] += v
    ans = ans+((c-b)*v)
    print(ans)


# Fixed code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)
A = Counter(A)
bc = [tuple(map(int, input().split())) for i in range(Q)]
for b, c in bc:
    v = A.pop(b, None)
    if v:
        A[c] += v
        ans = ans+((c-b)*v)
    print(ans)
# Buggy code:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
sums = sum(a)
d = {}

for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1

for i in range(q):
    b,c = map(int, input().split())
    if b in d:
        sums += d[b]*(c-b)
        if c in d:
          d[c] += d[b]
        else:
          d[c] = d[b]
  		d[b] = 0
    print(sums)

# Fixed code:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
sums = sum(a)
d = {}

for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1

for i in range(q):
    b,c = map(int, input().split())
    if b in d:
        sums += d[b]*(c-b)
        if c in d:
          d[c] += d[b]
        else:
          d[c] = d[b]
        d[b] = 0
    print(sums)
# Buggy code:
n=int(input())
ls = list(map(int,input().split()))

ls = sorted(ls)
ans = sum(ls)
newls = [0]*(n+1)
for p in ls:
  newls[p] += 1
ls = newls

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


# Fixed code:
n=int(input())
ls = list(map(int,input().split()))

ls = sorted(ls)
ans = sum(ls)
newls = [0]*(100000+1+1)
for p in ls:
  newls[p] += 1
ls = newls

q=int(input())
for _ in range(q):
  b,c = map(int,input().split())
  
  tmp = ls[b]
  ans = ans + tmp*c - tmp*b
  ls[b] = 0
  ls[c] += tmp
  
  print(ans)
# Buggy code:
from collections import Counter
N = int(input())

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

counter = Counter(A)
sum_res = sum(A)

for _ in range(Q):
    bf,af = map(int,input().split())
    sum_res -= bf*counter[bf]
    sum_res += af*counter[af]
    
    counter[af] += counter[bf]
    counter[bf] = 0
    
    print(sum_res)

# Fixed code:
from collections import Counter
N = int(input())

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

counter = Counter(A)
sum_res = sum(A)
#print(sum_res,counter)
for _ in range(Q):
    bf,af = map(int,input().split())
    sum_res -= bf*counter[bf]
    sum_res += af*counter[bf]
    
    counter[af] += counter[bf]
    counter[bf] = 0
    
    print(sum_res)
# Buggy code:
from collections import Counter

# print('input >>')
N = input()
As = list(map(int,(input().split())))
Q = int(input())
BCs = []
for _ in range(Q):
    BCs.append(tuple(map(int,(input().split()))))

counter = dict(Counter(As))
sum_ = sum(As)

for BC in BCs:
    sa = BC[1] - BC[0]
    sum_ += counter[BC[0]] * sa
    if not BC[1] in counter:
        counter[BC[1]] = 0
    counter[BC[1]] = counter[BC[1]] + counter[BC[0]]
    counter[BC[0]] = 0
    # print(counter)
    print(sum_)

# Fixed code:
from collections import Counter

# print('input >>')
N = input()
As = list(map(int,(input().split())))
Q = int(input())
BCs = []
for _ in range(Q):
    BCs.append(tuple(map(int,(input().split()))))

counter = dict(Counter(As))
sum_ = sum(As)

for BC in BCs:
    if not BC[0] in counter:
        counter[BC[0]] = 0
    if not BC[1] in counter:
        counter[BC[1]] = 0
    sa = BC[1] - BC[0]
    sum_ += counter[BC[0]] * sa
    counter[BC[1]] = counter[BC[1]] + counter[BC[0]]
    counter[BC[0]] = 0
    # print(counter)
    print(sum_)
# Buggy code:
N = int(input())
A = list(map(int,input().split()))
summary = sum(A)
d = {}
for a in A:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
    
Q = int(input())
for _ in range(Q):
  B, C = list(map(int,input().split()))
  b = d[B]
  d[B] = 0
  if C in d:
    d[C] += b
  else:
    d[C] = b
  summary = summary + b * (C - B)
  print(summary)

# Fixed code:
N = int(input())
A = list(map(int,input().split()))
summary = sum(A)
d = {}
for a in A:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
    
Q = int(input())
for _ in range(Q):
  B, C = list(map(int,input().split()))
  if B not in d:
    b = 0
  else:
    b = d[B]
    d[B] = 0
  if C in d:
    d[C] += b
  else:
    d[C] = b
  summary = summary + b * (C - B)
  print(summary)
# Buggy code:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
temp=sum(a)
import collections
ca=collections.Counter(a)
print(ca)
for i in range(q):
  b,c=map(int,input().split())
  ba=ca[b]
  temp=temp-b*ba+c*ba
  ca[b]=ca[b]-ba
  ca[c]=ca[c]+ba


# Fixed code:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
temp=sum(a)
import collections
ca=collections.Counter(a)
for i in range(q):
  b,c=map(int,input().split())
  ba=ca[b]
  temp=temp-b*ba+c*ba
  print(temp)
  ca[b]=ca[b]-ba
  ca[c]=ca[c]+ba
# Buggy code:
def sum_dict(d, sum, b, c):
    val = 0
    if b in d:
        val = d[b]
        sum -= (b * val)
        del d[b]
        d[c] = d.get(c, 0) + val
        sum += (c * val)
    return sum, d
    
n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
s = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    s, d = sum_dict(d, b, c)
    print(s)

# Fixed code:
def sum_dict(d, sum, b, c):
    val = 0
    if b in d:
        val = d[b]
        sum -= (b * val)
        del d[b]
        d[c] = d.get(c, 0) + val
        sum += (c * val)
    return sum, d
    
n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
s = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    s, d = sum_dict(d, s, b, c)
    print(s)