 The Mighty Divisible Number
Submissions: 714   Accuracy: 13.01%   Difficulty: Easy   Marks: 2

Given four numbers X, Y, Z and N. Your task is to find smallest N digit Number that is divisible by all the three numbers X, Y and Z.
Note: If no such number can be formed then print "-1".

Input:
The first line of the input contains an integer T, denoting the number of test cases. Then T test case follows. The only line of each test case contains four space separated integers denoting the values of X, Y, Z and N respectively.

Output:
For each test case output the smallest N digit number divisible by X, Y and Z. If no such number can be formed then print "-1".

Constraints:
1<=T<=103
1<=X,Y,Z<=103
1<=N<=18

Example:
Input:

3
2 3 5 4
4 5 6 3
3 5 7 2
Output:
1020
120
-1

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: harshitsidhwa

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.