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/2 | 1/2 | |||||
| 1/6 | 1/2 | 1/3 | ||||
| 0 | 1/4 | 1/2 | 1/4 | |||
| -1/30 | 0 | 1/3 | 1/2 | 1/5 | ||
| 0 | -1/12 | 0 | 5/12 | 1/2 | 1/6 | |
| 1/42 | 0 | -1/6 | 0 | 1/2 | 1/2 | 1/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:
Given $m$ and $k$, write a program that computes $F(m, k)$.
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$.
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$.