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]; bool dp[2][M]; int dy[] = {0,-1,0,1,0}, dx[] = {0,0,1,0,-1}; bool table[5][5]; int y,x; int main(){ while(cin >> n,n){ for(int i=0;i<n;i++){ for(int j=0;j<16;j++)cin >> sch[i][j]; } for(int i=0;i<M;i++)dp[0][i] = false; dp[0][4] = !sch[0][5] && !sch[0][6] && !sch[0][9] && !sch[0][10]; for(int i=0;i<n-1;i++){ int now = i&1, nxt = 1-now; for(int j=0;j<M;j++)dp[nxt][j] = false; for(int j=0;j<M;j++){ if(dp[now][j]){ for(int ii=0;ii<4;ii++){ for(int jj=0;jj<4;jj++){ table[ii][jj] = ((i<5)?