import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int m = Integer.parseInt(sa[1]); sa = br.readLine().split(" "); long[] a = new long[m]; long ans = 0; for (int i = 0; i < m; i++) { a[i] = Integer.parseInt(sa[i]); ans += a[i] * a[i]; } int q = Integer.parseInt(br.readLine()); PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < q; i++) { sa = br.readLine().split(" "); int c = Integer.parseInt(sa[0]) - 1; int k = Integer.parseInt(sa[1]); int d = Integer.parseInt(sa[2]) - 1; ans -= a[c] * a[c]; ans -= a[d] * a[d]; a[c] -= k; a[d] += k; ans += a[c] * a[c]; ans += a[d] * a[d]; pw.println(ans); } pw.flush(); br.close(); } }