#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T begin, T end) {
  for (T i = begin; i != end; ++i) cerr << *i << " ";
  cerr << endl;
}
inline bool valid(int x, int y, int W, int H) {
  return (x >= 0 && y >= 0 && x < W && y < H);
}
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int ddx[8] = {1, 0, -1, 0, 0, -1, -1, 1};
int ddy[8] = {0, 1, 0, -1, 0, 1, -1, -1};
int N;
int scd[365][4][4];
int cont[4][4];
int nx, ny;
int day;
bool dfs() {
  if (day == N) return true;
  for (int y = (0); y < (int)(4); ++y)
    for (int x = (0); x < (int)(4); ++x) cont[y][x]++;
  for (int dy = (0); dy < (int)(2); ++dy)
    for (int dx = (0); dx < (int)(2); ++dx) {
      if (scd[day][dy + ny][dx + nx] == 1) return false;
      cont[dy + ny][dx + nx] = 0;
    }
  for (int y = (0); y < (int)(4); ++y)
    for (int x = (0); x < (int)(4); ++x)
      if (cont[y][x] >= 7) return false;
  for (int r = (0); r < (int)(5); ++r)
    for (int k = 1; k <= 2; k++) {
      int nextx = nx + ddx[r] * k;
      int nexty = ny + ddy[r] * k;
      bool ok = true;
      for (int dy = (0); dy < (int)(2); ++dy)
        for (int dx = (0); dx < (int)(2); ++dx)
          ok &= valid(nextx + dx, nexty + dy, 4, 4);
      if (ok) {
        int tmpx = nx, tmpy = ny;
        int tmpcont[4][4];
        memcpy(tmpcont, cont, sizeof(cont));
        nx = nextx;
        ny = nexty;
        day++;
        if (dfs()) return true;
        day--;
        ny = tmpy;
        nx = tmpx;
        memcpy(cont, tmpcont, sizeof(cont));
      }
    }
  return false;
}
int main() {
  while (scanf("%d", &N) != EOF && N != 0) {
    for (int i = (0); i < (int)(N); ++i) {
      for (int y = (0); y < (int)(4); ++y)
        for (int x = (0); x < (int)(4); ++x) scanf("%d", &scd[i][y][x]);
    }
    nx = 1;
    ny = 1;
    day = 0;
    memset(cont, 0, sizeof(cont));
    if (dfs()) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}
