n = int(input())
a = [int(i) for i in input().split()]
sa  = sorted(a)

q = int(input())
b = []
for _ in range(q):
    b.append([int(i) for i in input().split()])


for i in range(q):
    idx = -1
    seta = set(sa)
    if b[i][0] in seta:
         idx = sa.index(b[i][0])
    # print(idx)

    if idx != -1:
        while (True):
            if idx < n and sa[idx] == b[i][0]:
                sa[idx] = b[i][1]
                idx += 1
            else:
                break
    # print(sa)
    print(sum(sa))

