#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair P; typedef pair PP; const ll MOD=998244353; const double PI=acos(-1); int main(){ int N,M; cin>>N>>M; map mp; for(int i=1;i<=M;i++){ ll a; cin>>a; mp[i]=a; } ll ans=0; for(auto [c,num]:mp){ ans+=1LL*num*num; } int Q; cin>>Q; vector outputans(Q); for(int q=0;q>c>>k>>d; ans-=mp[c]*mp[c]; ans-=mp[d]*mp[d]; mp[c]-=k; mp[d]+=k; ans+=mp[c]*mp[c]; ans+=mp[d]*mp[d]; // for(auto [v,num]:mp){ // cout<<"v="<