/// Author : Nguyễn Thái Sơn - K18 - KHMT - UIT
/// Training ICPC 2024
#include<bits/stdc++.h>
/// #pragma GCC optimize("O3,unroll-loops")
/// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define fi first
#define se second
#define TASK "test"
#define pb push_back
#define EL cout << endl
#define Ti20_ntson int main()
#define in(x) cout << x << endl
#define all(x) (x).begin(),(x).end()
#define getbit(x, i) (((x) >> (i)) & 1)
#define cntbit(x) __builtin_popcount(x)
#define FOR(i,l,r) for (int i = l; i <= r; i++)
#define FORD(i,l,r) for (int i = l; i >= r; i--)
#define Debug(a,n) for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> vii;
typedef unsigned long long ull;
typedef vector<vector<int>> vvi;
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
const int N = 5e5 + 5;
const int oo = INT_MAX;
const int mod = 1e9 + 7;
const int d4x[4] = {-1, 0, 1, 0} , d4y[4] = {0, 1, 0, -1};
const int d8x[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int n, a[N];
bool dp[370][13][8][8][8][8];
inline void Read_Input() {
dp[1][6][1][1][1][1] = true;
cin >> n;
}
inline void Solve() {
FOR(i, 1, n) {
FOR(j, 1, 16)
cin >> a[i];
FOR(vt, 1, 11)
FOR(o1, 0, 6)
FOR(o2, 0, 6)
FOR(o3, 0, 6)
FOR(o4, 0, 6) {
if (dp[i][vt][o1][o2][o3][o4] == false) continue;
/// xet cach di len tren
/// vt = 6 -> new_vt = 2
/// 2 - 3
/// 6 - 7
int new_vt = vt - 4;
int a1 = vt;
int a2 = vt + 1;
int a3 = vt + 4;
int a4 = a3 + 1;
/// chung ta co duoc bang con a1, a2, a3, a4
if (a[a1] == 0 && a[a2] == 0 && a[a3] == 0 && a[a4] == 0) {
/// co the di vao
/// co bao quat duoc goc nao hay khong
/// 1 - 4 - 13 - 16
if (a1 == 1) new_o1 = 0;
if (a2 == 4) new_o2 = 0;
if (a3 == 13) new_o3 = 0;
if (a4 == 16) new_o4 = 0;
dp[i + 1][new_ct][new_o1][new_o2][new_o3][new_o4] = true;
}
/// chu y len tren 1 hoac 2 buoc.
/// Tuy nhien can luu y : di ra khoi bang
/// xet cach di xuong duoi
/// xet cach di sang trai
/// xet cach di sang phai
}
}
}
Ti20_ntson {
freopen(TASK".INP","r",stdin);
freopen(TASK".OUT","w",stdout);
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
// cin >> T;
while (T -- ) {
Read_Input();
Solve();
}
}
Ly8vIEF1dGhvciA6IE5ndXnhu4VuIFRow6FpIFPGoW4gLSBLMTggLSBLSE1UIC0gVUlUCi8vLyBUcmFpbmluZyBJQ1BDIDIwMjQKCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CgovLy8gI3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk8zLHVucm9sbC1sb29wcyIpCi8vLyAjcHJhZ21hIEdDQyB0YXJnZXQoImF2eDIsYm1pLGJtaTIsbHpjbnQscG9wY250IikKCiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBUQVNLICJ0ZXN0IgojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIEVMIGNvdXQgPDwgZW5kbAojZGVmaW5lIFRpMjBfbnRzb24gaW50IG1haW4oKQojZGVmaW5lIGluKHgpIGNvdXQgPDwgeCA8PCBlbmRsCiNkZWZpbmUgYWxsKHgpICh4KS5iZWdpbigpLCh4KS5lbmQoKQojZGVmaW5lIGdldGJpdCh4LCBpKSAoKCh4KSA+PiAoaSkpICYgMSkKI2RlZmluZSBjbnRiaXQoeCkgX19idWlsdGluX3BvcGNvdW50KHgpCiNkZWZpbmUgRk9SKGksbCxyKSBmb3IgKGludCBpID0gbDsgaSA8PSByOyBpKyspCiNkZWZpbmUgRk9SRChpLGwsc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KG8xLCAwLCA2KQogICAgICAgICAgICAgICAgRk9SKG8yLCAwLCA2KQogICAgICAgICAgICAgICAgICAgIEZPUihvMywgMCwgNikKICAgICAgICAgICAgICAgICAgICAgICAgRk9SKG80LCAwLCA2KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZHBbaV1bdnRdW28xXVtvMl1bbzNdW280XSA9PSBmYWxzZSkgY29udGludWU7CgogICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8vIHhldCBjYWNoIGRpIGxlbiB0cmVuCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLy8gdnQgPSA2IC0+IG5ld192dCA9IDIKICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vLyAyIC0gMwogICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8vIDYgLSA3CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgbmV3X3Z0ID0gdnQgLSA0OwoKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGludCBhMSA9IHZ0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50IGEyID0gdnQgKyAxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50IGEzID0gdnQgKyA0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50IGE0ID0gYTMgKyAxOwoKICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vLyBjaHVuZyB0YSBjbyBkdW9jIGJhbmcgY29uIGExLCBhMiwgYTMsIGE0CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYVthMV0gPT0gMCAmJiBhW2EyXSA9PSAwICYmIGFbYTNdID09IDAgJiYgYVthNF0gPT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vLyBjbyB0aGUgZGkgdmFvCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8vIGNvIGJhbyBxdWF0IGR1b2MgZ29jIG5hbyBoYXkga2hvbmcKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLy8gMSAtIDQgLSAxMyAtIDE2CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGExID09IDEpIG5ld19vMSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGEyID09IDQpIG5ld19vMiA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGEzID09IDEzKSBuZXdfbzMgPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChhNCA9PSAxNikgbmV3X280ID0gMDsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZHBbaSArIDFdW25ld19jdF1bbmV3X28xXVtuZXdfbzJdW25ld19vM11bbmV3X280XSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8vIGNodSB5IGxlbiB0cmVuIDEgaG9hYyAyIGJ1b2MuCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLy8gVHV5IG5oaWVuIGNhbiBsdXUgeSA6IGRpIHJhIGtob2kgYmFuZwoKICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vLyB4ZXQgY2FjaCBkaSB4dW9uZyBkdW9pCgogICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8vIHhldCBjYWNoIGRpIHNhbmcgdHJhaQoKICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vLyB4ZXQgY2FjaCBkaSBzYW5nIHBoYWkKCgogICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgfQp9CgpUaTIwX250c29uIHsKICAgIGZyZW9wZW4oVEFTSyIuSU5QIiwiciIsc3RkaW4pOwogICAgZnJlb3BlbihUQVNLIi5PVVQiLCJ3IixzdGRvdXQpOwogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IGNpbi50aWUoMCk7IGNvdXQudGllKDApOwogICAgaW50IFQgPSAxOwovLyAgICBjaW4gPj4gVDsKICAgIHdoaWxlIChUIC0tICkgewogICAgICAgIFJlYWRfSW5wdXQoKTsKICAgICAgICBTb2x2ZSgpOwogICAgfQp9CgoK