In this problem, we assume that the Earth is a perfect sphere.
For two positions

on the equator, the
west distance 
is defined as the distance from

to

if you keep going west, the
east distance 
is defined as the distance from

to

if you keep going east.
We called

is to the west of

if

,

is to the east of

if

. Noticed that

might be neither to the west nor to the east of

.
¶ A
direction matrix 
is defined as a

matrix satisfying these conditions:
- For each integer
such that
,
. - For each integer pair
such that
and
,
.
A
direction matrix 
is
real if there are
distinct positions

on the equator satisfying these conditions:
- All points meet the anticlockwise order when we look down at the equator from above the north pole.
- For each integer pair
such that
and
, if
,
is to the west of
, otherwise
is to the east of
.
Now you are given a
direction matrix 
, but some

and

are replaced by

. If you can replace each

by

or

, how many
real direction matrix you can get? Print the number modulo

.