After a hard struggle, DreamGrid was finally admitted to a university. Now he is having trouble calculating the limit of the ratio of two polynomials. Can you help him?

DreamGrid will give you two polynomials of a single variable \(x\) (eg. x^2-4x+7) or constant integers, and then he will tell you an integer \(x_0\). Your job is to find out the limit of a ratio consisting of these two polynomials (or constant integers) when \(x\) tends to \(x_0\). The first polynomial is the numerator and the second one is the denominator.

The first line of input contains an integer \(T\) (\(1 \le T \le 50\)), which indicates the number of test cases. For each test case:

The first two lines describe two polynomials or constant integers, consisting of integers, 'x', '+', '-', and '^' without any space. The coefficients range from -9 to 9, and the exponents range from 1 to 9 (If the exponent is 1, it will be omitted and won't be displayed as '^1'). The operaters will be seperated by integers or 'x' (You won't see '-+x' in the input).

The third line is the integer \(x_0\), ranging from -9 to 9.

It's guaranteed that there won't be two same exponents in the same polynomial, and the numerator and denominator won't be both constant 0.

Output 1 line for each case.

If the limit exists, you should output it as the simplest fration (eg. -1, -1/6, 0, 3/2, 2, 3). Otherwise, output "INF" (not including the quotation marks).

提交代码