def main():
    N = int(input())
    A = list(map(int,input().split()))
    Q = int(input())
    for i in range(Q):
        B, C = list(map(int,input().split()))
        D = [j for j, x in enumerate(A) if x == B]
        for k in D:
            A[k] = C
        print(sum(A))
 
 
 
if __name__ == '__main__':
    main()