Kunal and his Puja Vacation.

0

0 votes
Easy-Medium
Problem

Kunal loves Puja Vacation . But this time he is getting bored .
Reason ? Ask Kunal
So , he started playing a game .
The rules are as follow
->He took three primes a , b and c.
->He took all the multiples of prime and put in a container
->Then , he sorts the container in non decending order
->Then , he removes all the duplicates

Now he want to find Kth number of the container

Kunal is unable to think these days.so, he want your help
Can you help him out?

Input:

First line contains T, the number of test cases that follow. Next T lines, each contains three prime a , b, c and K.

Output: For each test case, print the desired result in separate lines.

Constraints:
1 ≤ T ≤ 100000
0 ≤ K ≤ 1000000000000000
1 ≤ a,b,c ≤ 10000

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Here a=2,b=3,c=5
Now multiples of 2 are 2,4,6,8,10,12,14....
Now multiples of 3 are 3,6,9,12,15,18....
Now multiples of 5 are 5,10,15,20,25....

After merging and sorting we have
2,3,4,5,6,6,8,9,10,12,12,14,15,15...

After removing duplicates ,
2,3,4,5,6,8,9,10,12,14,15

Now 10th number is 14

Editor Image

?