N = int(input())
nums = list(map(int, input().split()))
Q = int(input())
operations = [list(map(int, input().split())) for _ in range(Q)]

mappings = [ 0 for __ in range(10**5+1)]
answer = 0

for b, c in operations:
  mappings[b] = c

for num in nums:
  answer += mappings[num]

print(answer)