N=int(input())
A=''
A+=input.split()
Q=int(input())
B=list(input().split() for i in range(Q))
for j in  range(Q):
    A.replace(B[j][0],B[j][1])
    for k in A:
        c=0
        c +=int(k)
        print(c)