N = int(input())
arr = list(map(int,input().split()))
for i in range(int(input())):
    a,b = map(int,input().split())
    for i in range(N):
        if arr[i] == a:
            arr[i] = b
    print(sum(arr))
