#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
int n;
int ba[365][4][4];
bool memo[366][3][3][7 * 7 * 7 * 7];
bool visited[366][3][3][7 * 7 * 7 * 7];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int hogex[] = {0, 0, 2, 2};
int hogey[] = {0, 2, 0, 2};
bool solve(int day, int y, int x, int S) {
  if (visited[day][y][x][S]) return memo[day][y][x][S];
  visited[day][y][x][S] = 1;
  if (day == n) return memo[day][y][x][S] = 1;
  int tmp = S;
  int norain[4];
  for (int i = 0; i < (int)4; ++i) {
    norain[i] = tmp % 7;
    tmp /= 7;
  }
  for (int i = 0; i < (int)2; ++i)
    for (int j = 0; j < (int)2; ++j)
      if (ba[day][y + i][x + j]) return memo[day][y][x][S] = 0;
  for (int i = 0; i < (int)4; ++i) {
    int xx = x, yy = y;
    if (i) xx += dx[i], yy += dy[i];
    while (0 <= xx && xx <= 2 && 0 <= yy && yy <= 2) {
      int nextS = 0;
      int tmp = 1;
      bool f = 0;
      for (int j = 0; j < (int)4; ++j) {
        if (!(xx == hogex[j] && yy == hogey[j])) {
          if (norain[j] == 6) f = 1;
          nextS += tmp * (norain[j] + 1);
        }
        tmp *= 7;
      }
      if (!f && solve(day + 1, yy, xx, nextS)) {
        return memo[day][y][x][S] = 1;
      }
      yy += dy[i];
      xx += dx[i];
    }
  }
  return memo[day][y][x][S] = 0;
}
int main() {
  while (cin >> n, n) {
    for (int i = 0; i < (int)n; ++i)
      for (int j = 0; j < (int)4; ++j)
        for (int k = 0; k < (int)4; ++k) cin >> ba[i][j][k];
    memset(visited, 0, sizeof(visited));
    cout << (solve(0, 1, 1, 0) ? 1 : 0) << endl;
  }
}
