Faulhaber's Triangle

Time limit1sMemory limit128 MB

Problem

The sum of the $m$-th powers of the integers from $1$ to $n$ is

$$S(n, m) = \sum_{j=1}^{n} j^m,$$

which can be written as a polynomial in $n$ of degree $m+1$:

$$S(n, m) = \sum_{k=1}^{m+1} F(m, k), n^k.$$

For example,

$$S(n, 1) = 1 + \dots + n = \tfrac{1}{2}n^2 + \tfrac{1}{2}n$$ $$S(n, 2) = 1 + \dots + n^2 = \tfrac{1}{3}n^3 + \tfrac{1}{2}n^2 + \tfrac{1}{6}n$$ $$S(n, 3) = 1 + \dots + n^3 = \tfrac{1}{4}n^4 + \tfrac{1}{2}n^3 + \tfrac{1}{4}n^2$$ $$S(n, 4) = 1 + \dots + n^4 = \tfrac{1}{5}n^5 + \tfrac{1}{2}n^4 + \tfrac{1}{3}n^3 - \tfrac{1}{30}n$$

The coefficients $F(m, k)$ form Faulhaber's triangle:

1
1/21/2
1/61/21/3
01/41/21/4
-1/3001/31/21/5
0-1/1205/121/21/6
1/420-1/601/21/21/7

In $F(m, k)$, the row index $m$ is counted from the top starting at $0$, and the column index $k$ is counted from the left starting at $1$.

Faulhaber's triangle can be built as follows:

  1. For $j > 1$, $F(i, j) = \dfrac{i}{j} , F(i-1, j-1)$.
  2. $F(i, 1)$ is chosen so that the entries in row $i$ add up to $1$.

Given $m$ and $k$, write a program that computes $F(m, k)$.

Input

The first line contains the number of test cases $P$ ($1 \le P \le 1000$). Each test case is a single line containing $m$ and $k$ separated by a space, with $0 \le m \le 400$ and $1 \le k \le m+1$.

Output

For each test case, output $F(m, k)$. If the value is an integer, print it as an integer; otherwise print it as a reduced fraction in the form $p/q$.