n = int(input())
arr = list(map(int,input().split()))
for i in range(int(input())):
    q , c = map(int,input().split())
    for i in range(n):
        if arr[i] == q:
            arr[i] = c
    print(sum(arr))