if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    SUM = []
    for i in range(Q):
        B, C = list(map(int, input().split()))
        A = [C if a == B else a for a in A]
        SUM.append(sum(A))

    for s in SUM:
        print(s)
