n = int(input())

nums = input().split()

q = int(input())

ans = []

for _ in range(q):
    b, c = input().split()
    
    nums = " ".join(nums)
    nums = nums.replace(b, c)
    nums = nums.split()
    t = [int(num) for num in nums]
    ans.append(sum(t))

for a in ans:
    print(a)