import numpy as np
def main():
    n = int(input())
    A = np.array(list(map(int, input().split())))
    q = int(input())
    #print(A)
    for _ in range(q):
        b, c = map(int, input().split())
        A = np.where(A == b, c, A)
        print(np.sum(A))


if __name__ == "__main__":
    main()
