#P2768. 珍珠项链

珍珠项链

Description

Xiao L decides to make a unique pearl necklace using KK kinds of pearls. A pearl necklace is a sequence of pearls, and its length is the number of pearls in the sequence. Now he is very rich and owns NN pearls of each kind. Two necklaces are considered different if, when laid out straight, their pearls are in different linear orders. Xiao L wonders how many different necklaces of lengths from 11 to NN he can make. To show wealth, each necklace must use all KK kinds of pearls. Output the answer modulo 12345678911234567891.

This should be easy for you! If you can help Xiao L solve this problem, he might give you 1/41/4 of his assets!

Input Format

The input contains multiple testdata. The first line is an integer TT, which is the number of testdata. Each testdata occupies one line and contains two integers NN and KK, separated by a space.

Output Format

For each testdata, output exactly one line containing one integer, which is the number of kinds of necklaces.

2
2 1
3 2
2
8

Hint

  • 40%: 1N1000001 \le N \le 100000, 0K300 \le K \le 30.
  • 100%: T10T \le 10, 1N1091 \le N \le 10^9, 0K300 \le K \le 30.
  • 70%–100%: time limit 1010 ms.

Translated by ChatGPT 5