n = int(input())
arr = list(map(int,input().split()))
t = int(input())
while t:
    t-=1
    k,r = map(int,input().split())
    for i in range(n):
        if arr[i] == k:
            arr[i]=r
    print(sum(arr))