import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); long a[] = new long[m + 1]; for(int i = 1; i <= m; i++)a[i] = sc.nextInt(); int q = sc.nextInt(); long sum = 0; for(int h = 1; h <= m; h++){ sum += a[h]*a[h]; } for(int i = 0; i < q; i++){ int a1 = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); sum -= a[a1]*a[a1] + a[c] * a[c]; a[a1] -= b; a[c] += b; sum += a[a1]*a[a1] + a[c] * a[c]; System.out.println(sum); } } }