Under construction

Still being built. Things may change

Braid Squared

Time limit1sMemory limit1024 MB

Summary
Given a braid-squared expression and a polynomial, check whether integrating the polynomial twice, with constants C and D, produces that expression.
Level

Medium4 of 10

Topics
Implementation, Math, String
Solved
No attempts yet

문제

Daik Manga was doing calculus when the difficulty became unbearable, and a fantasy struck him: what if the integral (∫\int) were a cute girl with two braids? Using the power of that fantasy, he brought Integral-chan into being.

Daik Manga was delighted by Integral-chan's birth and began to analyze her traits. Integral-chan hugs every expression nearby. The hugged expression is then integrated twice out of joy. Because the expression is integrated once for each braid, the problem calls it a two-braid expression, or a braid-squared expression.

Integral-chan performs indefinite integration, and integrating twice means applying indefinite integration two times. On the first integration, the antiderivative of the given polynomial gets a constant CC added. On the second integration, a different constant DD is added.

There is a problem. Integral-chan hugs expressions so often that the original expression can no longer be recovered. The original expressions and the braid-squared expressions are now mixed together, and Integral-chan is depressed with guilt.

Daik Manga does not want to see Integral-chan depressed. So he picks a braid-squared expression and an arbitrary polynomial, and wants to know whether that polynomial is the correct original expression before the braid-squaring. But Daik Manga shouted that he hates math and ran away.

Help Daik Manga comfort Integral-chan. Determine whether each polynomial, when hugged, produces the given braid-squared expression.

입력

The first line contains the number of test cases TT (1≤T≤1001 \le T \le 100). Each test case contains a braid-squared expression ii and a polynomial mm chosen by Daik Manga, separated by a space.

Both ii and mm are written as ....

Each has the form x^.

  • If the degree is 00, omit x^.
  • If the degree is 11, omit ^.
  • If the coefficient is 11, omit the coefficient.
  • If the sign of the first term of ii or mm is +, omit the sign.
  • In ii, a term whose coefficient is C has sign +, and its degree is 1.
  • In ii, a term whose coefficient is D has sign +, and its degree is 0.
  • A term means the coefficient of the degree- term of the current polynomial is .

The degree is an integer from 00 to 500500.

  • The terms of ii and mm are given in decreasing order of degree.
  • No two terms in the same polynomial have the same degree.

The sign is + or -.

The coefficient is a positive integer, a positive rational number, C, or D.

  • In mm, the coefficient is never C or D.
  • In mm, the coefficient is at most 124 750 000124\,750\,000.
  • In ii, every coefficient other than C or D is at most 500500.
  • A rational coefficient is written as /.
    • In ii, the numerator is an integer from 11 to 500500.
    • In mm, the numerator is an integer from 11 to 124 750 000124\,750\,000.
    • The denominator is an integer from 22 to 500500.
    • The numerator and denominator are coprime, so the fraction is in lowest terms.

출력

For each test case, print Yes if mm is the original expression of ii. Otherwise, print No.

힌트

The integration rule used here is ∫xndx=1n+1xn+1+C\int x^n \mathrm{d}x = \frac{1}{n+1}x^{n+1} + C.

Examples1

  1. Example 1

    Input
    4
    1/3x^3+Cx+D 2x
    1/6x^3-1/2x^2+Cx+D x-1
    1/2x^2+Cx+D 1
    84x^2+Cx+D 168x
    
    Expected output
    Yes
    Yes
    Yes
    No