SP9445 CLONES - Attack of the Clones

Description

A boolean function is a function of the form f: B $ _{n} $ -> B, where B = {0, 1} and n is a non-negative integer called the arity of the function. Some Boolean functions are projections: p $ _{n} $ $ ^{k} $ (x $ _{1} $ , ..., x $ _{n} $ ) = x $ _{k} $ . And given an m-ary function f, and n-ary functions g $ _{1} $ , ..., g $ _{m} $ , we can construct another n-ary function: h(x $ _{1} $ , ..., x $ _{n} $ ) = f(g1(x $ _{1} $ , ..., x $ _{n} $ ), ..., gm(x $ _{1} $ , ..., x $ _{n} $ )), called their composition. A set of functions closed under composition and containing all projections is called a clone. One trivial clone is a set of all boolean functions. Some of the special clones are: - Z is a set of 0-preserving functions: f(0, ..., 0) = 0; - P is a set of 1-preserving functions: f(1, ..., 1) = 1; - D is a set of self-dual functions: !f(x $ _{1} $ , ..., x $ _{n} $ ) = f(!x $ _{1} $ , ..., !x $ _{n} $ ); - A is a set of affine functions: the functions satisfying that if f(a $ _{1} $ , ..., c, ..., a $ _{n} $ ) = f(a $ _{1} $ , ..., d, ..., a $ _{n} $ ) then f(b $ _{1} $ , ..., c, ..., b $ _{n} $ ) = f(b $ _{1} $ , ..., d, ..., b $ _{n} $ ), where c and d are at some position i. This should hold for every valid i, a $ _{1} $ , ..., a $ _{n} $ , b $ _{1} $ , ... b $ _{n} $ , c and d. Now we are interested how many n-ary functions are there in some combinations of mentioned above sets. For example, for n = 2, there are exactly 8 functions in Z, 4 functions in the intersection of Z and P, 8 function in the complement of A and so on.

Input Format

The first line of the input file contains n - the arity of the boolean functions we are looking at. The second line contains the q - number of queries. Each of the next q lines will describe a query. The query is a set expression. The expression will contain the following characters: 'Z', 'P', 'D', 'A' denoting the sets, described above; 'v' - which is set union; '^' - which is set intersection; '!' which is complement; '\\' which is set difference; and also '(' and ')' to define operations priority. Operations in brackets have higher priority. Otherwise the '!' operation has the higher priority and 'v', '^' and '\\' are of the same priority. It is guaranteed that the expression will be correct. See samples for some examples of set expressions.

Output Format

For each query in the input print how many n-ary function are in the set described by the according set expression modulo 1000003.