import sys
def main():
  input = sys.stdin.readline
  N=int(input())
  L=list(map(int,input().split()))
  Q=int(input())
  for i in range(Q):
    A,B=map(int,input().split())
    R=[B for K in L if K==A]
    L=[i for i in L if i!=A]
    L.extend(R)
    print(sum(L))
if __name__ == '__main__':
    main()