#include <bits/stdc++.h>
using namespace std;
struct S {
  int g[4][4];
  bool r[4][4];
  int y, x;
};
int main() {
  try {
    for (int N; cin >> N, N;) {
      vector<S> d[366];
      d[0].push_back({{}, {}, 1, 1});
      for (int i = 0; i < N; i++) {
        int s[16];
        for (int j = 0; j < 16; j++) {
          cin >> s[j];
        }
        for (auto e : d[i]) {
          for (int k = 0; k < 3; k++) {
            for (int l = 0; l < 3; l++) {
              if (k != e.y && l != e.x) continue;
              auto cs = e;
              cs.y = k;
              cs.x = l;
              for (int m = 0; m < 4; m++) {
                for (int n = 0; n < 4; n++) {
                  cs.g[m][n]++;
                }
              }
              for (int m = 0; m < 2; m++) {
                for (int n = 0; n < 2; n++) {
                  int y = k + m;
                  int x = l + n;
                  cs.g[y][x] = 0;
                  cs.r[y][x] = true;
                  if (s[y * 4 + x]) goto next;
                }
              }
              if (*max_element(cs.g[0], cs.g[4]) >= 7) goto next;
              d[i + 1].push_back(cs);
            next:;
            }
          }
        }
      }
      bool f = false;
      for (auto e : d[N]) {
        f |= count(e.r[0], e.r[4], true) == 16;
      }
      cout << f << endl;
    }
  } catch (...) {
  }
}
