def main():
    N = int(input())
    A = list(map(int,input().split()))
    Q = int(input())
    B = [0 for i in range(Q)]
    C = [0 for i in range(Q)]
    
    for q in range(Q):
        b,c = map(int,input().split())
        A = [c if a == b else a for a in A]
        print(sum(A))
    
if __name__ == '__main__':
    main()