\problemname{LogDB}

A LogDB database is filled with facts. A fact is a name with a
body consisting of a
parenthesized list of names. This is  similar to a function call: 

\[
fact1(arg1, arg2 ,arg\_3,4,4) thing(p1,arg2,p3).
\]

$fact1$ is the name of the fact and the list of names in the body are
the arguments of the fact. $thing$ is another fact.

The names in the list are separated by commas and optional
whitespace. There will be at least one name in the list.

Names consist of alphanumeric characters
(a-z,A-Z,0-9) plus `$\_$'. However, the name
of a fact and the names in the body cannot start with an `$\_$'.

Names, parentheses, and commas may be preceded and followed by
whitespace. However a fact or query cannot be split across lines.

Facts with different numbers of arguments are different facts.

A fact may appear multiple times in the database.

Queries are like facts except the argument list can contain 
variables. Variables are names that start with `$\_$'.  

A query searches the database for facts with the same name as the
query that have the same number of arguments as the query and where the
names in the fact body match the names in the query body in their
respective positions.

A variable consisting of only `$\_$' is special and will match any
name.

A variable other than `$\_$' will also match any name but if that variable
appears more than once in a query, the names in the fact must be the same.

A query:
\[
fact1(arg1,\_,\_,\_check,\_check)
\]

will match $fact1(arg1, arg2 ,arg\_3,4,4)$.

Variables are only defined in the query they appear in. They are not
necessarily related if they are in different queries.

\section*{Input}

The input consists of two sections: facts and queries. Judged data has
no syntax errors.

The fact section consists of a series of lines of at most $200$ characters.
That section is terminated by a blank line. Each line consists of facts
which may (or may not) be separated by whitespace. The fact section will consist
of no more than $200$ lines.

The query section consists of a series of lines of at most $200$
characters. That section is terminated by end-of-file.  Each line is
a query. The query section will consist of no more than $200$ lines.

\section*{Output}

For each query print the number of facts returned by the query as an
integer with no leading or trailing whitespace and no unnecessary leading
zeros. If a matching fact appears multiple times in the database, count each occurrence.

