n = int(input())
num = list(map(int,input().split()))
q = int(input())
ans=0
for i in range(q):
    b,c = map(int,input().split())
    for j in range(n):
        if num[j] == b:
            num[j] = c 
        ans += num[j]
    print(ans)
    ans = 0