


Output the sum modulo 10 ^ 9 + 7.
If ‘X’ = 1, ‘Y’ = 1 and ‘Z’ = 0 then the output will be 84.
Explanation : 3 + 4 + 34 + 43 = 84
The first line contains an integer ‘T’ which denotes the number of test cases or queries to be run. Then the test cases are as follows.
The first and only line of each test case contains three space-separated integers denoting ‘X’, ‘Y’, and ‘Z’ respectively.
For each test case, print a single line containing the sum of all the numbers formed by having 3 at most ‘X’ times, having 4 at most ‘Y’ times, and having 5 at most ‘Z’ times as a digit.
The output of each test case will be printed in a separate line.
You don’t need to print anything; It has already been taken care of. Just implement the given function.
1 <= T <= 50
0 <= X, Y, Z <= 10
Where ‘T’ is the number of test cases and ‘X’, ‘Y’ and ‘Z’ are the three integers.
Time limit: 1 sec.
The basic idea is to make all possible combinations of numbers having ‘X’ 3s, ‘Y’ 4s and ‘Z’ 5s as digits and adding them to get the desired result.
In this approach we will be using Dynamic programming. We will find all combinations of numbers having exactly X - 3’s, Y - 4’s and Z - 5’s, and then add them to get our desired sum.
For this, we will create two 3D-DP arrays, let’s say “num[N][N][N]”, “sum[N][N][N]”, where ‘N’ is the maximum possible value of ‘X’, ‘Y’ and ‘Z’:
sum[i][j][k] = 10 * (sum[i - 1][j][k] + sum[i][j - 1][k] + sum[i][j][k - 1])
+ 3 * num[i - 1][j][k]
+ 4 * num[i][j - 1][k]
+ 5 * num[i][j][k - 1]