def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())

    for _ in range(q):
        l = []
        b, c = map(int, input().split())
        l = [i if i != b else c for i in a]
        print(sum(l))
        a = l[:]


if __name__ == "__main__":
    main()
