import numpy as np
def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    BC = [list(map(int, input().split())) for _ in range(Q)]


    Adict = dict()
    for a in A:
        Adict[a] = Adict.get(a, 0) + 1
    
    for b, c in BC:
        if b in Adict:
            tmp = Adict[b]
            Adict[c] = Adict.get(c, 0) + tmp
            Adict.pop(b)
        
        goukei = sum([k*v for k, v in Adict.items()])
        
        print(goukei)


if __name__ == '__main__':
    main()
