import numpy as np
if __name__ == "__main__":
    n = int(input().strip())
    a = np.array(input().strip().split()).astype(int)
    q = int(input().strip())
    bc = np.array([input().strip().split() for i in range(q)]).astype(int)

    for i in range(q):
        a[a == bc[i][0]] = bc[i][1]
        print(np.sum(a))