def main():
    N=int(input())
    A=[int(x) for x in input().split()]
    Q=int(input())
    ans=[]
    for _ in range(Q):
        B,C=map(int, input().split())
        A=[C if x==B else x for x in A]
        ans.append(str(sum(A)))
    print('\n'.join(ans))
    return

if __name__=='__main__':
    main()
