#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; /* string chadd(string sum, ll x){ ll up = 0, tmp = 0; if (sum.size() >= 6){ up = stoll(sum.substr(0, sum.size() - 5)); tmp = stoll(sum.substr(sum.size() - 5)); } else if (sum != "") tmp = stoll(sum); else tmp = 0; tmp += x; if (tmp >= 1e5){ up += tmp/1e5; tmp = tmp%100000; } sum = ""; if (up) sum += to_string(up); string stmp = to_string(tmp); if (up) stmp = std::string(std::max(0, 5-(int)stmp.size()), '0') + stmp; sum += stmp; return sum; } */ int main() { int n, m, q; cin >> n >> m; vector a(m); for (int i = 0; i < m; i++) cin >> a[i]; cin >> q; for (int i = 0; i < q; i++){ ll c, k, d, sum1 = 0; //string sum1 = ""; cin >> c >> k >> d; a[c-1] -= k; a[d-1] += k; for (auto x : a){ sum1 += x*x; } cout << sum1 << "\n"; } }