import numpy as np

n=int(input())
a=np.array(list(map(int, input().split())))
q=int(input())

def func(a):
  for i in range(q):
    b,c=map(int, input().split())
    a[a==b]=c
    print(np.sum(a))

func(a)