Matrix and Chef WA

I have solved this Problem but why is this Solution gives WA. Instead of using last non-zero element as given in editorial I am using last known element of the sequence i.e. if I want to compute A[i] then I will compute it using A[i-1] and B[i][i-1] and other equation will be formed by using A1=0 and B[1][i]. Can anyone find what is error ?