import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    a = LI()
    q = I()
    b = [0]*q
    c = [0]*q
    for i in range(q):
        b[i], c[i] = MI()
    a_sum = sum(a)
    a_dict = dict()
    for ai in a:
        a_dict[str(ai)] = a.count(ai)
    for i in range(q):
        temp1 = 0
        if str(b[i]) in a_dict:
            temp1 = a_dict[str(b[i])]
        temp2 = 0
        if str(c[i]) in a_dict:
            temp2 = a_dict[str(c[i])]
        a_dict[str(c[i])] = temp1+temp2
        a_sum += (c[i]-b[i])*temp1
        print(a_sum)

if __name__ == '__main__':
    main()