B. Better than Bitcoin
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Examples
Input
2
3 7 7
8 2 5
Output
2
4
Input
3
1859 19 7
1967 2 17
2000 29 29
Output
213519321
1086566377
0