spoj#BHAT007. Nikhil Problem
Nikhil Problem
Nikhil is a very interesting and creative charater. Nikhil had best friend whose name was Kasat. Kasat was inspired from SKG ,a mathematics professor having an experience of 30 years of teaching in IIT Kanpur , So he decided to open Mathematics classes named as “SAI KRIPA GANIT BHANDAR” .But unfortunately no one joined his classes as the fees he charged was too less compared to other institutions ,so people thought that he is not a good teacher and his wait for the students continued ,but the best friend Nikhil was not able to see his friend Kasat in such a gloomy situation. So to boost kasat’s spirit he became the only student of the “SAI KRIPA GANIT BHANDAR” .
Nikhil learned addition multiplication in different number system (like binary number system : base 2, octal number system : base 8, Hexagonal number system , Kasat number system : base 7, Shrotriya number system : base 3, bhat number system : base 13, rajnikant number system base:100, ravikant number system base:101 etc. ).
Nikhil was given daily assignment on this but helping friends and being lazy are two different things ,all he could help kasat was to join coaching classes and completing those complex assignment were not his cup of tea. Kasat thought an innovative idea for Nikhil to sharp his mind in the field of number system. So , he gives the same type of problem daily in assignment.
Problem :
x(b1) + y(b1) = z1
x(b2) + y(b2) = z2
x(b): number x in base b number system .
x and y are two numbers ( must be valid in decimal (i.e. base 10), base b1 and base b2 number system like 1A is not valid in base 10 i.e. decimal number system but valid in base 16,17,18,etc )
z1 and z2 is the result of addition of x and y number in base b1 and b2 number system respectively .
If z1 and z2 are similar then answer is "yes" else "No".
0<= x < 2100
0<= y < 2100
1<= b1 < 100
1<= b2 < 100
Your task is to write the program to solve the problem of Nikhil.
Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing four integers x,y (0 <= x,y <= 2^100) and b1,b2 (1 <=b1,b2<= 100).
Output
Your program should print one line of output for each test case. Output can either be "yes" or "no" .
Example
Input:</p>
3
10 01 2 10
11 11 2 10
12 12 8 10
Output:
yes
no
yes