N = int(input())
li = list(map(int,input().split()))
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split())
    li = [(C if li[j]==B else li[j]) for j in li]
    sum = 0
    for i in range(N):
        sum = sum+li[i]
    print(sum)