The Chef has a huge square napkin of size 2n X 2n. He folds the napkin n-3 times. Each time he folds its bottom side over its top side, and then its right side over its left side. After each fold, the side length of the napkin is reduced by half. The Chef continues folding until there remains a 8x8 sheet, lying flat on a table.
Oh, did I forget to mention that the Chef was cooking a new brown colored curry while folding the napkin. He drops some brown colored gravy onto some cells in the folded 8x8 napkin. When he drops the gravy, it soaks through all the cells below it.
Now the Chef unfolds the napkin to its original size. There are now many curry stained brown colored cells in the napkin. They form several separate regions, each of which is connected. Could you help the Chef count how many regions of brown cells are there in the napkin?
Note that two cells are adjacent if they share a common edge (they are not considered adjacent if they only share a corner). Two cells are connected if we can go from one cell to the other via adjacent cells. A region is a maximal set of cells such that every two of its cells are connected.
Please see the example test case for more details.

-----Input-----
The first line contains t, the number of test cases (about 50). Then t test cases follow. Each test case has the following form:
- The first line contains N (3 ≤ N ≤ 109)
- Then, 8 lines follow. Each line is a string of 8 characters, 0 or 1, where 1 denotes a stained brown cell in the folded napkin.

-----Output-----
For each test case, print a single number that is the number of disconnected brown regions in the unfolded napkin. Since the result may be a very large number, you only need to print its remainder when dividing by 21945.

-----Example-----
Input:
3
3
01000010
11000001
00000000
00011000
00011000
00010100
00001000
00000000
4
01000010
11000001
00000000
00011000
00011000
00010100
00001000
00000000
1000000000
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111

Output:
6
22
1

-----Output details-----

Case 1 and 2: There are 6 brown regions in the 8x8 napkin. If we unfold it once, it has 22 brown regions: 11 regions in the top half and 11 regions in the bottom half (as shown in the figure above).
Case 3: All cells of the napkin are stained, so there is always one brown region, no matter how many times the Chef unfolds the napkin.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "import sys\nt = int(sys.stdin.readline())\n\ndef identify(x, y):\n    rows[x][y] = '2'\n\n    r = 0\n    if x == 0:\n        r |= 1\n    elif rows[x-1][y] == '1':\n        r |= identify(x-1, y)\n    if x == 7:\n        r |= 4\n    elif rows[x+1][y] == '1':\n        r |= identify(x+1, y)\n    if y == 0:\n        r |= 2\n    elif rows[x][y-1] == '1':\n        r |= identify(x, y-1)\n    if y == 7:\n        r |= 8\n    elif rows[x][y+1] == '1':\n        r |= identify(x, y+1)\n    return r\n\nP = 21945\n\nwhile t:\n    t-=1\n    n = int(sys.stdin.readline())-3\n\n    rows = [list(sys.stdin.readline().strip()) for i in range(8)]\n    total = 0\n    for i in range(8):\n        for j in range(8):\n            if rows[i][j] == '1':\n                r = identify(i,j)\n                # print '\\n'.join([''.join(ro) for ro in rows])\n                # print r\n                if n == 0:\n                    total += 1\n                    # print total\n                    continue\n                if r == 0:\n                    total += pow(2, 2*n, P)\n                elif r == 1 or r == 2 or r == 4 or r == 8:\n                    total += pow(2, 2*n-1, P)\n                    if r == 1 or r == 2:\n                        total += pow(2, n, P)\n                elif r == 5 or r == 10:\n                    total += pow(2, n, P)\n                elif r == 3 or r == 6 or r == 12 or r == 9:\n                    total += pow(2, 2*n-2, P)\n                    if r == 3:\n                        total += 3 + 2*pow(2, n-1, P) - 2\n                    elif r == 6 or r == 9:\n                        total += pow(2, n-1, P)\n                elif r == 15:\n                    total += 1\n                else:\n                    total += pow(2, n-1, P)\n                    if r == 11 or r == 7:\n                        total += 1\n                # print total\n    print(total % P)\n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 22197