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
def sumBetween(a, b):
    sumToA = a * (a - 1) / 2
    return (b * (b + 1) / 2) - sumToA

#print sumBetween(1, 100)

cases = int(raw_input())

for _ in xrange(cases):
    N, A, B, C = map(int, raw_input().strip().split())

    au = min(N, A)

    count = 0
   # count2 = 0
    for a in xrange(0, au + 1):
        rest = N - a
        bu = min(rest, B)
      #  for b in xrange(0, bu + 1):
      #      p = min(C, rest - b) + 1
      #      count2 += p

        sumRest = sumBetween(rest - bu + 1, rest + 1)

        if (C < rest - bu):
            sumRest = (C + 1) * (bu + 1)
        elif (C < rest):
            sumRest = sumBetween(rest - bu + 1, C + 1)
            sumRest += (C + 1) * (rest - C)

        count += sumRest

    print count
    #, count2

#                                 C + 1
# wertebereich p: rest - b + 1 .... rest + 1