Problem1079--Distribute numbers

1079: Distribute numbers

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

Tom and Peter like to play with numbers. You have to distribute N1 integers to Tom and N2 integers to Peter
 You cannot give the same numbers to both Tom and Peter. Also, Tom doesn't like the numbers that are divisible by 
prime number X and Peter doesn't like the numbers that are divisible by a prime number Y. 
So you cannot distribute the numbers to them that they do not like. Find the minimum value of N that you can use to distribute from set 1, 2, 3 ... N. You can choose not to distribute some numbers at all.

Input

Input format
The first line contains an integer T which are the number of test cases
 The first line of each test case contains N1 N2 X Y four integers.  
1<=T<= 100
1<= N1, N2 < 1,000,000,000
N1 + N2 <= 1,000,000,000
2 <= X < Y <= 100,000

Output


Output format
For each test case, output one integers which is the minimum N satisfies the requirement.

Sample Input Copy

1
3 1 2 3

Sample Output Copy

5

HINT

In the first sample, you give the set of numbers {1, 3, 5} to Tom and the set of numbers {2} to Peter. 

Source/Category