def main():
    N=int(input())
    A=[int(x) for x in input().split()]
    Q=int(input())
    BC=[list(map(int, input().split())) for _ in range(Q)]
    for bc in BC:
        A=[bc[1] if x==bc[0] else x for x in A]
        print(sum(A))
    return

if __name__=='__main__':
    main()
