7496: Borrow

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:1

题目描述

Alice, Bob and Cindy are good friends. They go shopping together and buy the same. However, they don't bring the same units money with themselves so one of them suggests that the one with the most money should borrow 1 unit money to someone else with equal probability. That is to say, if they have x,y,z(x≥y≥z)units money separately, the one with xunits money (if multiple people have the most then they decide one should borrow with equal probability) will give 1 unit to one of his/her friends with equal probability. After that, they have x−1,y+1,zor x−1,y,z+1units money.
This act will last until everyone has the same units money. Three smart guys want to know the expected times of this act or if this situation will never come.
 

输入格式

The input contains several test cases.
The first line contains a single integer T, indicating the number of test cases.
Following Tlines, each line contains three integer x,y,zindicating the money of three guys.
x+y+z≤106,∑x+y+z≤3×106
 

输出格式

For each test case, if the situation that everyone has the same units money will never come then print −1, else print the expected times in a line. If the expected times is PQ, you should output P⋅Q−1mod998244353, where Q−1denotes the multiplicative inverse of Qmodulo 998244353.
 

输入样例 复制

3
1 2 3
1 1 4
5 1 4

输出样例 复制

2
3
-1