SP179 WORDEQ - Word equations

Description

Every non-empty sequence of elements 0 and 1 is called a binary word. A word equation is an equation of the form _x_ $ _{1} $ _x_ $ _{2} $ ..._x $ _{l} $_ = _y_ $ _{1} $ _y_ $ _{2} $ ..._y_ _$ _{r} $_ , where _x_ _$ _{i} $_ and _y_ _$ _{j} $_ are binary digits (0 or 1) or variables i.e. small letters of English alphabet. For every variable there is a fixed length of the binary words that can be substituted for this variable. This length is called a length of variable. In order to solve a word equation we have to assign binary words of appropriate length to all variables (the length of the word assigned to the variable _x_ has to be equal to the length of this variable) in such a way that if we substitute words for variables then both sides of the equation (which are binary words after substitution) become equal. For a given equation compute how many distinct solutions it has.

Input Format

The number of equations _t_ is in the first line of input, then _t_ descriptions of equations follow separated by an empty line. Each description consists of 6 lines. An equation is described in the following way: in the first line of the description there is an integer _k_, 0

Output Format

For each equation your program should output one line with the number of distinct solutions.