n = int(input())
a = list(input().split())
q = int(input())
ans = []

for _ in range(q):
    b, c = input().split()
    atmp = " ".join(a)
    atmp = atmp.replace(b, c)
    a = atmp.split(" ")
    anew = [int(x) for x in a]
    ans.append(sum(anew))
    
print(*ans, sep='\n')