Welcome to ZOJ
Select Problem
ZOJ Problem Set - 3999
The Limit

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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).

Sample Input


Sample Output



\(\lim\limits_{x \to 1}\frac{x^2-2x+1}{x^2-1} = 0\), and \(\lim\limits_{x \to 9}\frac{9x^8}{-9x^9} = -\frac{1}{9}\).

Author: XU, Yukun
Source: ZOJ Monthly, January 2018
Submit    Status