Hey, Math Enthusiasts! Can you solve this?

Revision en11, by salehin_076923, 2025-05-23 08:18:56

This is my first own problem created on Polygon! So I am excited!

I request you to try first before reading the tutorial!

You can submit your solution through this invitation link: https://mirror.codeforces.com/contestInvitation/1d814de17ea46b3255e85ecac66b0fd6adcf138d

Problem Name: Arithmetic Geometric Series

time limit per test: 1 second

memory limit per test: 256 megabytes

Problem Description

Salehin has recently learnt about Arithmetic Series (where the difference between 2 consecutive terms remains constant e.g. $$$1+2+3+\ldots +n$$$ Here Constant Difference $$$=2-1=3-2=1$$$) and Geometric Series (where the ratio between 2 consecutive terms remains constant e.g. $$$3+3^2+3^3+\ldots 3^n$$$ Here Constant Ratio $$$=\frac{3^2}{3}=\frac{3^3}{3^2}=3$$$).

Now an idea came to his mind to combine or mashup these 2 series and he named it "Arithmetic Geometric Series"! Arithmetic Geometric Series forms of 2 parameters: $$$x$$$ & $$$n$$$. Arithmetic Geometric Series for $$$x$$$ & $$$n$$$, $$$AG(x,n)=x+2\cdot x^2+3\cdot x^3+4\cdot x^4+\ldots +n\cdot x^n=\sum_{k=1}^{n}{k\cdot x^k}$$$

Salehin wants to determine the values of the series for different values of $$$x$$$ & $$$n$$$. But he is very tired to do such calculations! So he needs your help!

Hence you have to determine the value of $$$AG(x,n)$$$ for given values of $$$x$$$ and $$$n$$$.

Since the answer can be very large, output $$$AG(x,n)$$$ modulo $$$998$$$ $$$244$$$ $$$353$$$.

Input

The first line contains one integer $$$t(1\leq t\leq 10^4)-$$$ the number of test cases. Then $$$t$$$ test cases follows.

Each test case consists of only one line which contains $$$x(0\leq x\leq 10^5)$$$ & $$$n(1\leq n\leq 10^9)-$$$ the parameters of Arithmetic Geometric Series.

Output

For each test case, print one integer $$$-$$$ $$$AG(x,n)$$$ modulo $$$998$$$ $$$244$$$ $$$353$$$.

Example

input


3 5 5 4 4 7 100000 1000000000 0 4

output

1641

2930

145636

110642754

0

Note

In the first test case, $$$AG(3,5)= 3+2\cdot 3^2+3\cdot3^3+4\cdot 3^4+5\cdot3^5=1641$$$

In the second test case, $$$AG(5,4) = 5+2\cdot5^2+3\cdot5^3+4\cdot5^4=2930$$$

Tutorial
Code

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en15 English salehin_076923 2025-05-23 08:31:50 0 (published)
en14 English salehin_076923 2025-05-23 08:28:06 43
en13 English salehin_076923 2025-05-23 08:25:25 233
en12 English salehin_076923 2025-05-23 08:21:42 74
en11 English salehin_076923 2025-05-23 08:18:56 7 Tiny change: ' 0;\n}\n\n\n</spoi' -> ' 0;\n}\n\n```\n\n</spoi'
en10 English salehin_076923 2025-05-23 08:18:26 1839
en9 English salehin_076923 2025-05-23 08:14:54 3
en8 English salehin_076923 2025-05-23 08:13:52 738
en7 English salehin_076923 2025-05-23 07:57:51 70
en6 English salehin_076923 2025-05-23 07:53:41 106
en5 English salehin_076923 2025-05-23 07:48:41 126
en4 English salehin_076923 2025-05-23 07:45:06 3
en3 English salehin_076923 2025-05-23 07:42:38 2
en2 English salehin_076923 2025-05-23 07:40:35 28
en1 English salehin_076923 2025-05-23 07:37:28 2920 Initial revision (saved to drafts)