def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    for _ in range(Q):
        B, C = map(int, input().split())
        for j in range(N) :
            if A[j] == B : 
                A[j] = C
        print(sum(A))

if __name__ == "__main__":
    main()