import sys
n = int(input())
an = list(map(int, sys.stdin.readline().rstrip().split()))
q = int(input())

import numpy as np
from collections import deque

sum = np.sum(an)
ans = deque()

for _ in range(q):
    b,c = map(int, input().split())
    for i in range(n):
        if b == an[i]:
            an[i]=c
            sum += c-b
    ans.append(sum)

while ans:
    print(ans.popleft())