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

b=[]
c=[]
for i in range(q):
    d,e=input().split()
    b.append(int(d))
    c.append(int(e))

for i in range(q):
    for j in range(len(b)):
        if a[i] == b[j]:
            a[i]=c[j]
            # if a[-1] ==b[j]:
            #     a[-1]=c[i]
print(sum(a))
    # print(a)
# print(a)
# print(b)
# print(c)