import collections
N = int(input())
List = list(map(str, input().split()))
Q = int(input())
x = [0] * Q
y = [0] * Q
for i in range(Q):
    x[i], y[i] = map(str, input().split())
    y[i]=int(y[i])

wa=0
for i in List:
    wa+=int(i)

for i in range(Q):
    c = collections.Counter(List)
    num=c['{}'.format(x[i])]
    wa+=num*(y[i]-int(x[i]))
    List=[s.replace('{}'.format(x[i]), '{}'.format(str(y[i]))) for s in List]
    print(wa)