
def D():
    import numpy as np
    n= int(input())
    Alist = list(map(int,input().split()))
    Anp = np.array(Alist)
    q = int(input())
    l = []
    for i in range(q):
        b,c= map(int,input().split())
        Anp = np.where(Anp==b,c,Anp)
        print(np.sum(Anp))




D()
