def main():
  n = int(input())
  a = list(map(int,input().split()))
  q = int(input())
  for _ in range(q):
    b, c = map(int, input().split())
    sum=0
    for i in range(0,n):
      if(a[i]==b):
        a[i]=c
        sum+=a[i]
    print(sum)
main()