Dreary Design (Large1)

Count RGB triples with each component between 0 and K whose largest and smallest values differ by at most V.

Medium6CombinatoricsMathNo attempts yetTime limit5sMemory limit512 MB

Problem

A color is a triple of component values giving the levels of red, green, and blue. Each component is an integer from 00 to KK, inclusive. For example, in the color system with K=3K = 3, the colors (0,2,3)(0, 2, 3) and (0,3,2)(0, 3, 2) are two of the distinct colors available.

A color is bland if every pair of its component values differs by at most VV. For example, in a system with K=2K = 2 and V=1V = 1, the color (2,1,1)(2, 1, 1) is bland: the red and green components differ by 11, the red and blue components differ by 11, the green and blue components differ by 00, and none of those differences exceeds 11. The color (2,1,0)(2, 1, 0) is not bland, because its red and blue components differ by more than 11.

Mr. Turner paints gloomy landscapes and wants to design a color system with many bland colors in it. Given KK and VV, count the distinct bland colors.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains two integers KK and VV separated by a space.

Limits

  • 1T1001 \le T \le 100
  • 0K25550 \le K \le 2555
  • 0V5550 \le V \le 555
  • VKV \le K
  • Every answer fits in a signed 32-bit integer.

Output

For each test case, print one line of the form Case #x: y, where x is the test case number starting from 11 and y is the number of distinct bland colors.

Note

With K=1K = 1 and V=1V = 1 there are eight possible colors: (0,0,0)(0, 0, 0), (0,0,1)(0, 0, 1), (0,1,0)(0, 1, 0), (0,1,1)(0, 1, 1), (1,0,0)(1, 0, 0), (1,0,1)(1, 0, 1), (1,1,0)(1, 1, 0), and (1,1,1)(1, 1, 1). All eight are bland, because no two components differ by more than 11.

With K=1K = 1 and V=0V = 0 the same eight colors are possible, but only (0,0,0)(0, 0, 0) and (1,1,1)(1, 1, 1) are bland.