#include <bits/stdc++.h>
using namespace std;
struct cl {
  int a, b, c, d, id;
};
bool operator<(const cl& x, const cl& y) {
  return x.a * 10000 + x.b * 1000 + x.c * 100 + x.d * 15 + x.id <
         y.a * 10000 + y.b * 1000 + y.c * 100 + y.d * 15 + y.id;
}
bool operator==(const cl& x, const cl& y) {
  return x.a == y.a && x.b == y.b && x.c == y.c && x.d == y.d && x.id == y.id;
}
inline bool ok(int x) { return x % 4 < 3 && x / 4 < 3; }
int mv[8] = {1, 2, -1, -2, 4, 8, -4, -8};
int main() {
  while (true) {
    int N;
    cin >> N;
    if (N == 0) break;
    cl be = cl{7, 7, 7, 7, 5};
    vector<cl> vc;
    vc.push_back(be);
    for (int i = 0; i < (N); ++i) {
      int x[16];
      for (int j = 0; j < (16); ++j) cin >> x[j];
      vector<cl> nvc;
      for (auto cloud : vc) {
        int a = cloud.a, b = cloud.b, c = cloud.c, d = cloud.d, id = cloud.id;
        if (x[id] || x[id + 1] || x[id + 4] || x[id + 5]) continue;
        for (int di = 0; di < (8); ++di) {
          int ni = id + mv[di];
          if (!ok(ni)) continue;
          a--, b--, c--, d--;
          if (ni == 0) a = 7;
          if (ni == 2) b = 7;
          if (ni == 8) c = 7;
          if (ni == 10) d = 7;
          if (a == 0 || b == 0 || c == 0 || d == 0) continue;
          nvc.push_back(cl{a, b, c, d, ni});
        }
      }
      sort((nvc).begin(), (nvc).end());
      nvc.erase(unique((nvc).begin(), (nvc).end()), nvc.end());
      vc = nvc;
    }
    cout << (vc.size() > 0) << endl;
  }
}
