#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << '(' << p.first << ',' << p.second << ')';
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& a) {
  os << '[';
  for (int i = int(0); i < int(a.size()); i++) os << (i ? " " : "") << a[i];
  return os << ']';
}
bool conflict(int c, int i, int j) { return c & 0x33 << i * 4 + j; }
bool left7days(unsigned long long b) {
  return b + 0x1111111111111111ull & 0x8888888888888888ull;
}
unsigned long long next(unsigned long long b, int i, int j) {
  return b + 0x1111111111111111ull & ~(0xff00ffull << (i * 4 + j) * 4);
}
namespace std {
template <>
struct hash<tuple<int, int, unsigned long long>> {
  size_t operator()(const tuple<int, int, unsigned long long>& t) const {
    const char* ptr = (const char*)(&t);
    size_t res = 2166136261;
    for (int i = int(0); i < int(sizeof(t)); i++) (res ^= *ptr++) *= 16777619;
    return res;
  }
};
}  // namespace std
int main() {
  for (int n; cin >> n && n;) {
    vector<int> cs(n);
    for (int i = int(0); i < int(n); i++)
      for (int j = int(0); j < int(16); j++) {
        int x;
        cin >> x;
        cs[i] |= x << j;
      }
    queue<tuple<int, int, unsigned long long>> q;
    q.emplace(1, 1, 0);
    for (int d = int(0); d < int(n); d++) {
      decltype(q) q2;
      unordered_set<tuple<int, int, unsigned long long>> vis;
      while (q.size()) {
        auto cur = q.front();
        q.pop();
        int i, j;
        unsigned long long b;
        tie(i, j, b) = cur;
        if (i < 0 || 3 <= i || j < 0 || 3 <= j) continue;
        if (conflict(cs[d], i, j) || left7days(b)) continue;
        if (vis.count(cur)) continue;
        vis.insert(cur);
        for (int k = int(0); k < int(4); k++)
          for (int l = int(0); l < int(2); l++) {
            int ni = i + "\xff\x1\0\0"[k] * (l + 1),
                nj = j + "\0\0\xff\x1"[k] * (l + 1);
            q2.emplace(ni, nj, next(b, i, j));
          }
      }
      swap(q, q2);
    }
    bool res = false;
    while (q.size()) {
      res |= !left7days(get<2>(q.front()));
      q.pop();
    }
    cout << res << endl;
  }
}
