from sys import *
ip = stdin.readline
N = int(ip())
arr = list(map(int,ip().split()))
for i in range(int(ip())):
    a,b = map(int,ip().split())
    for i in range(N):
        if arr[i] == a:
            arr[i] = b
    print(sum(arr))
