64 cubes are packed into a four-by-four-by-four lattice. (No, not the kind used to make salad. Forget lettuce! Think of a three-dimensional grid.) Each cube is either black or white.
The lattice configuration is described by a String containing four elements of 16 characters each. Imagine the lattice resting on a table with one face oriented north. If we cut the lattice into four slices parallel to the tabletop, then the first String describes the topmost slice, the second describes the second slice from the top, and so on. Each String lists the contents of a slice row by row from north to south, and from west to east within each row. Every character has one of two values: "B" stands for a black cube, "W" for a white one.
We say that a line consists of four cubes, all the same color, arranged sequentially in any orthogonal or diagonal direction. A line may be such that consecutive cubes touch each other with their faces, or such that they touch with their edges, or such that they touch with their corners. All four cubes must be aligned in the same direction. Two lines are distinct if they are not formed of the same four cubes.
Given a lattice configuration and a color, count the number of distinct lines formed by cubes of that color.