#K13851. Taco Ingredient Conversion

    ID: 24004 Type: Default 1000ms 256MiB

Taco Ingredient Conversion

Taco Ingredient Conversion

You are given N ingredients where the i-th ingredient has quantity \(q_i\). You are also provided with M conversion operations. Each conversion is represented by a triple \((A, B, C)\). For each conversion operation, you should create a copy of the original list of quantities and then check if the \(A\)-th ingredient equals \(B\) (i.e. \(q_A = B\)). If the condition is satisfied, update the quantity of the \(A\)-th ingredient to \(C\) and compute the total sum of the ingredients, i.e., \(\sum_{i=1}^{N} q_i\). Otherwise, output "Invalid" for that particular conversion.

Apply each conversion exactly once (always using the original quantities for each conversion) and print the result of each conversion on a new line.

inputFormat

The first line contains an integer \(N\) indicating the number of ingredients.

The second line contains \(N\) space-separated integers representing the quantities \(q_1, q_2, \ldots, q_N\).

The third line contains an integer \(M\) denoting the number of conversion operations.

The following \(M\) lines each contain three integers \(A\), \(B\), and \(C\) representing a conversion operation.

outputFormat

For each conversion, print the total quantity obtained by replacing the \(A\)-th ingredient from \(B\) to \(C\) if the current quantity is exactly \(B\), otherwise print "Invalid". Each result should be printed on a separate line.

## sample
3
200 300 400
2
2 300 150
3 400 800
750

1300

</p>