Programmers can overload functions in many programming languages. Function overloading means defining several functions that share the same name but differ in the number or types of their parameters. In some languages, such as Ada, the return type can be overloaded as well: you may declare several functions with exactly the same name and parameters but different return types.
Here is an example of function overloading.
1: char f(float x, int y)
2: char f(float x, float y)
3: float f(float x, float y)
4: float g(float x, int y)
5: float g(int x, float y)
Given these declarations, you can write code containing variable declarations and function calls such as the following.
1: float a = 1.0, b = 2.0;
2: int c = 3;
3: float d = g(c, f(a, b));
The first and second declarations of f cannot be used here. The third f, however, matches: its parameter types are f(float, float), and its return type float is exactly what g(int, float) requires. So using the third f together with the second g resolves the call uniquely.
If, for each function name, we number its declarations from 1 in order (the serial number), the call above can be written as:
d = g2(c, f3(a, b))
With the same declarations, no combination of functions satisfies c = g(a, f(a, c)).
Finally, suppose we have the following declarations.
1: float x(float w)
2: int x(float w)
3: char y(float v)
4: char y(int v)
With these, the call char c = y(x(a)) (where float a) is ambiguous and cannot be used, because it can be interpreted in two ways depending on whether x returns float or int.
The input consists of several function declarations followed by several function calls.
Each function declaration is given on its own line in the following form.
name num_params param(1) param(2) ... param(num_params) rettype
name is the function name, param(i) is the data type of the i-th parameter, and rettype is the data type of the return value (there are no void functions in this problem). num_params is between 1 and 9 inclusive. Parameters have no names. A function name is a single lowercase letter and a data type is a single uppercase letter. Declarations that share the same name appear consecutively, and there are at most 500 declarations per name. No two declarations are completely identical in name, parameters, and return type.
As described above, the number attached to each declaration of a given name is called its serial number. The serial number starts at 1 when a new function name first appears and increases by 1 for each subsequent declaration of that name.
After all function declarations, a line containing # is given. From the next line on, function calls are given one per line.
A function call follows this grammar.
<function_call> := <data_type> = <right_hand_side>
<right_hand_side> := <fname> <num_params> <param_list>
<param_list> := <param> | <param_list> <param>
<param> := <data_type> | <right_hand_side>
<data_type> := <upper_case_letter>
<num_params> := '1' | '2' | ... | '9'
<fname> := <lower_case_letter>
:= and | are symbols used only in the grammar definition and do not appear in the actual input. The number of function-name calls within each function call does not exceed 500. After all function calls, a single # is given on the last line.
For each function call, output the following.
impossible.ambiguous together with the number of ways. If that number exceeds 1000, output > 1000 instead of the number (that is, ambiguous > 1000).