def f() return gets.split(" ").map{|e| e.to_i} end def g(xs) return xs.map{|e| e**2}.sum end n,m=f() xs=f() q=gets.to_i q.times{ c,k,d=f() xs[c-1],xs[d-1]=xs[c-1]-k,xs[d-1]+k puts g(xs) }