Dreary Design (Small)

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

Easy2Brute forceMathNo attempts yetTime limit5sMemory limit512 MB

Problem

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

A color is bland when every pair of its component values differs by at most VV. In a system with K=2K = 2 and V=1V = 1, the color (2,1,1)(2, 1, 1) is bland: red and green differ by 1, red and blue differ by 1, green and blue differ by 0, and no difference exceeds 1. The color (2,1,0)(2, 1, 0) is not bland, because red and blue differ by more than 1.

Turner paints gloomy landscapes and wants 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 space separated integers KK and VV.

Limits

  • 1T1001 \le T \le 100
  • 0K2550 \le K \le 255
  • 0V1000 \le V \le 100
  • 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 xx is the test case number starting from 1 and yy is the number of distinct bland colors.

Hint

With K=1K = 1 and V=1V = 1 there are eight 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), and all eight are bland, so the answer is 8.

With K=1K = 1 and V=0V = 0 the same eight colors exist, but only (0,0,0)(0,0,0) and (1,1,1)(1,1,1) are bland, so the answer is 2.