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