#include <bits/stdc++.h>
using namespace std;
int dx[9] = {0, 1, 2, -1, -2, 0, 0, 0, 0};
int dy[9] = {0, 0, 0, 0, 0, 1, 2, -1, -2};
int in[365][4][4];
class state {
 public:
  int y, x, day;
  char m[4][4];
  state() {
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++) m[i][j] = 0;
    y = x = 1;
    day = 0;
  }
  bool operator<(const state &a) const {
    if (day != a.day) return day;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++)
        if (m[i][j] != a.m[i][j]) return m[i][j] < a.m[i][j];
    return false;
  }
  bool move(int i) {
    int nex = x + dx[i], ney = y + dy[i];
    if (nex < 0 || ney < 0 || nex + 1 >= 4 || ney + 1 >= 4) return false;
    x = nex;
    y = ney;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++) m[i][j]++;
    for (int i = y; i < y + 2; i++) {
      for (int j = x; j < x + 2; j++) m[i][j] = 0;
    }
    return true;
  }
};
bool check(state &now) {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (now.m[i][j] == 0 && in[now.day][i][j] == 1) return false;
      if (now.m[i][j] == 7) return false;
    }
  }
  return true;
}
bool solve(int lim, state now, set<state> &S) {
  if (S.find(now) != S.end()) return false;
  S.insert(now);
  if (now.day == lim) return true;
  for (int i = 0; i < 9; i++) {
    state next = now;
    next.day++;
    if (next.move(i) == true && check(next) && solve(lim, next, S)) return true;
  }
  return false;
}
int main() {
  int d;
  while (cin >> d && d) {
    for (int i = 0; i < d; i++) {
      for (int j = 0; j < 4; j++)
        for (int k = 0; k < 4; k++) cin >> in[i][j][k];
    }
    state ini;
    set<state> S;
    if (in[0][1][1] == 0 && in[0][1][2] == 0 && in[0][2][1] == 0 &&
        in[0][2][2] == 0 && solve(d, ini, S))
      puts("1");
    else
      puts("0");
  }
}
