#include <bits/stdc++.h>
using namespace std;
bool dp[366][16][8][8][8][8];
int dx[] = {-2, 2, -1, 1, 0, 0, 0, 0, 0};
int dy[] = {0, 0, 0, 0, 1, -1, 0, 2, -2};
int t[366][17], p[4], n;
int main() {
  while (cin >> n, n) {
    int ans = 0;
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 16; j++) cin >> t[i][j];
    dp[0][5][1][1][1][1] = 1;
    for (int a = 0; a < n - 1; a++)
      for (int b = 0; b < 16; b++)
        for (int c = 0; c < 7; c++)
          for (int d = 0; d < 7; d++)
            for (int e = 0; e < 7; e++)
              for (int f = 0; f < 7; f++)
                if (dp[a][b][c][d][e][f]) {
                  int x1 = b % 4, y1 = b / 4;
                  for (int i = 0; i < 9; i++) {
                    int x = x1 + dx[i], y = y1 + dy[i], flag = 0;
                    if (x < 0 || y < 0 || 2 < x || 2 < y) continue;
                    p[0] = y * 4 + x, p[1] = y * 4 + x + 1;
                    p[2] = (y + 1) * 4 + x, p[3] = (y + 1) * 4 + x + 1;
                    for (int k = 0; k < 4; k++)
                      if (t[a + 1][p[k]]) flag++;
                    if (!flag) {
                      if (p[0] == 0)
                        dp[a + 1][p[0]][0][d + 1][e + 1][f + 1] = 1;
                      else if (p[0] == 2)
                        dp[a + 1][p[0]][c + 1][0][e + 1][f + 1] = 1;
                      else if (p[0] == 8)
                        dp[a + 1][p[0]][c + 1][d + 1][0][f + 1] = 1;
                      else if (p[0] == 10)
                        dp[a + 1][p[0]][c + 1][d + 1][e + 1][0] = 1;
                      else
                        dp[a + 1][p[0]][c + 1][d + 1][e + 1][f + 1] = 1;
                    }
                  }
                }
    for (int b = 0; b < 16; b++)
      for (int c = 0; c < 6; c++)
        for (int d = 0; d < 6; d++)
          for (int e = 0; e < 6; e++)
            for (int f = 0; f < 6; f++)
              if (dp[n - 1][b][c][d][e][f]) ans++;
    if (t[0][5] || t[0][6] || t[0][9] || t[0][10]) ans = 0;
    cout << (ans ? 1 : 0) << endl;
  }
}
