#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int di[5] = {1, -1, 4, -4, 0};
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N;
  while (cin >> N, N) {
    queue<pair<int, vector<int>>> q[2];
    vector<int> tmp;
    tmp.push_back(0);
    tmp.push_back(0);
    tmp.push_back(0);
    tmp.push_back(0);
    int crt = 0, nxt = 1;
    q[crt].push(make_pair(5, tmp));
    for (int i = (0); i < (N); ++i) {
      vector<int> vi(16);
      for (int j = (0); j < (16); ++j) cin >> vi[j];
      while (!q[crt].empty()) {
        auto res = q[crt].front();
        q[crt].pop();
        int idx = res.first;
        vector<int>& buf = res.second;
        vector<int> p;
        for (int x = idx / 4 * 4; x <= idx / 4 * 4 + 2; ++x) p.push_back(x);
        for (int y = idx % 4; y <= idx % 4 + 8; y += 4) p.push_back(y);
        for (int idx_ : p) {
          if (i == 0 && idx_ != 5) continue;
          if (idx_ < 0 || idx_ % 4 == 3 || idx_ >= 12) continue;
          if (vi[idx_] || vi[idx_ + 1] || vi[idx_ + 4] || vi[idx_ + 5])
            continue;
          vector<int> xs = buf;
          if (idx_ != 0)
            ++xs[0];
          else
            xs[0] = 0;
          if (idx_ != 2)
            ++xs[1];
          else
            xs[1] = 0;
          if (idx_ != 8)
            ++xs[2];
          else
            xs[2] = 0;
          if (idx_ != 10)
            ++xs[3];
          else
            xs[3] = 0;
          if (xs[0] >= 7 || xs[1] >= 7 || xs[2] >= 7 || xs[3] >= 7) continue;
          q[nxt].push(make_pair(idx_, xs));
        }
      }
      swap(crt, nxt);
    }
    cout << (q[crt].empty() ? 0 : 1) << endl;
  }
  return 0;
}
