n = int(input())
arr = list(map(int, input().split()))
k = int(input())
s = sum(arr)
for _ in range(k):
    v = 0
    a,b = map(int, input().split())
    for i in range(len(arr)):
      if arr[i] == a:
        arr[i] = b
        v += 1
    s = s - (a*v) + (b*v)
    print(s)