def main():

  N=int(eval(input()))

  A=list(map(int,input().split()))

  s=sum(A)

  Q=int(eval(input()))

  d=[0]*(10**5 +1)#各数字の個数

  for i in A:

    d[i]+=1



  for i in range(Q):

    B,C=list(map(int,input().split()))

    s += (C-B)*d[B]

    print(s)

    d[C]+=d[B]

    d[B]=0



if __name__ == "__main__":

    main()
def main():

  N=int(eval(input()))

  A=list(map(int,input().split()))

  s=sum(A)

  Q=int(eval(input()))

  d=[0]*(10**5 +1)#各数字の個数

  ans=[]

  for i in A:

    d[i]+=1



  for i in range(Q):

    B,C=list(map(int,input().split()))

    s += (C-B)*d[B]

    ans.append(s)

    d[C]+=d[B]

    d[B]=0

    

  print(("\n".join(map(str, ans))))



if __name__ == "__main__":

    main()
def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    s = sum(A)
    Q = int(eval(input()))
    d = [0] * (10**5 + 1)  # 各数字の個数
    for i in A:
        d[i] += 1
    for i in range(Q):
        B, C = list(map(int, input().split()))
        s += (C - B) * d[B]
        print(s)
        d[C] += d[B]
        d[B] = 0


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    s = sum(A)
    Q = int(eval(input()))
    d = [0] * (10**5 + 1)  # 各数字の個数
    ans = []
    for i in A:
        d[i] += 1
    for i in range(Q):
        B, C = list(map(int, input().split()))
        s += (C - B) * d[B]
        ans.append(s)
        d[C] += d[B]
        d[B] = 0
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()

+    ans = [] -        print(s) +        ans.append(s) +    print(("\n".join(map(str, ans))))