def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    BC = [list(map(int, input().split())) for i in range(Q)]

    for i in range(Q):
        B, C = tuple(BC[i])
        for j in range(N):
            if A[j] == B:
                A[j] = C
        print(sum(A))


if __name__ == "__main__":
    main()
