Given an image consisting only lowercase letters, for each query you should count the number of patterns in the image.
Formally, an image is a matrix with $n$ rows and $m$ columns, and each cell of the matrix contains a character. Considering a string consisting of lowercase letters, we can place it horizontally or vertically, so it has following shapes:
We can bend it $90$ degrees, and we get some new shapes:
In a word, a pattern is a string with these $6$ possible shapes:
For example, pattern
abcd can have following shapes:
Kanari loves CV(Computer Vision), he writes a CNN(Convolutional Neural Network) to count the number of patterns in an image. Kanari is so cute, and the accuracy tends to $100\%$ after a long time parameter adjustment. Can you solve it too?