# Replacing 
def replace(arr, q):
    for cur, new in q:
        for i, num in enumerate(arr):
            if num == cur:
                arr[i] = new
        print(sum(arr))

n = int(input())
ar = list(map(int, input().rstrip().split()))
q = int(input())
qar = []
for i in range(q):
    x = list(map(int, input().rstrip().split()))
    qar.append(x)
replace(ar, qar)