1711 - Random at Random

Time Limit : 1 Second

Memory Limit : 128 MB

Submission: 8

Solved: 4

Description

Xiao Hua is a student who loves running. However, he is too fat to run fast.


As a straight A student of science and engineering, Xiao Hua developed a running-helper one day to accelerate himself while running. He called it the HKJA(Hong Kong Journalist Accelerator).


 


The HKJA’s operating mechanism is as follows: each acceleration contains n independent sections (where n is a non-negative random variable). Its expectation is μn and the variance is σn. During the ith independent acceleration-section, the HKJA gives the user a velocity increment values ai(where ai~N(μaa2) ). All the ais in i.i.d.(independent identical distribution). The result of the final acceleration is the sum of all a, denoted as S.


                                                                          

It is not difficult to find that the total speed increment S is also a random variable.


 


In order to test whether the acceleration effect is "steady", Xiao Hua would like to know, given the features of distribution which n and ai obey (given the expectations and variance), how much is the variance of random variable S ?

Input

The first line of the input file is a positive integer T1<=T<=20),indicating that there are T test cases.


As for each test casethere is only one line contains four integers representing μnσn2μaσa2.


 


0<|μa|<=100, 0<=μnna<=100.

Output

For each set of samples, output the variance of the random variable S.

sample input
4
2 0 10 4
2 3 6 4
5 2 -5 3
3 4 3 0
sample output
8
116
65
36
hint

Standard input and output.

 n~N(μ,σ2)means random variable nobeys normal distribution. The expectation is μ, the variance is σ2it is obvious that the variance isnon-negative.

source
sunzhenyu
© 2015 HUST ACMICPC TEAM. All Right Reserved.