#include using namespace std; int N,M; int A[1<<17]; int main() { cin>>N>>M; long ans=0; for(int i=1;i<=M;i++) { cin>>A[i]; ans+=(long)A[i]*A[i]; } int Q;cin>>Q; for(;Q--;) { int c,k,d;cin>>c>>k>>d; ans-=(long)A[c]*A[c]; ans-=(long)A[d]*A[d]; A[c]-=k; A[d]+=k; ans+=(long)A[c]*A[c]; ans+=(long)A[d]*A[d]; cout<