Statement 

Given N,A,B,C, find how many solutions exist to the equation : a + b + c ≤ N, such that 0 ≤ a ≤ A, 0 ≤ b ≤ B, 0 ≤ c ≤ C.


Input 

The first line contains the number of test cases T. Each test case contains 4 integers, N,A,B,C. 0 ≤ N,A,B,C ≤ 2500


Output 

Output T lines, one for each test case.


Sample Input 

2
4 3 2 1
1 1 1 1


Sample Output 

20
4
import sys


def sumcount(i):
    return (i * (i+1)) / 2

lines = sys.stdin.readlines()

numcase = int(lines.pop(0))

for i in xrange(0,numcase):
    n, amax, bmax, cmax = [int(num) for num in lines.pop(0).split(' ')]

    count = 0
    
    for a in xrange(0, min(int(amax), n)+1):
        sum = n - a
        if sum >= bmax + cmax:
            count += (bmax+1) * (cmax+1)
            continue
        min_num = bmax if bmax < cmax else cmax
        max_num = bmax if bmax >= cmax else cmax

        if sum <= min_num:
            count += sumcount(sum+1)
        elif sum > min_num and sum < max_num:
            count += sumcount(sum+1) - sumcount(sum-min_num)
        else:
            count += (sum+1)*(max_num+1) - sumcount(max_num) - sumcount(sum-min_num)

    sys.stdout.write(str(count) + '\n')