n = int(input())
a = list(map(int,input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
    # print(bc[i][0])
    # index = a.index(bc[i][0])
    index = [j for j, x in enumerate(a) if x == bc[i][0]]
    # print(index)
    for k in index:
        a[k] = bc[i][1]
    # a[index] = bc[i][1]
    print(sum(a))