Under construction

Still being built. Things may change

Hard Problem

Time limit1sMemory limit1024 MB

Summary
Sum (last element + 10) times f_m over even-length subsegments whose two halves have maxima differing by at most k, modulo 998244353.
Level

Hard8 of 10

Topics
Divide and conquer, Stack, Segment tree
Solved
No attempts yet

Statement

You are given an integer array a1,…,ana_1, \ldots, a_n. A subsegment of even length ai,…,ai+2m−1a_i, \ldots, a_{i + 2m - 1} is called good if ∣max⁡(ai,…,ai+m−1)−max⁡(ai+m,…,ai+2m−1)∣≤k\left|\max(a_i, \ldots, a_{i + m - 1}) - \max(a_{i + m}, \ldots, a_{i + 2m - 1})\right| \le k.

Define an integer sequence ff as follows:

  • f1=3240f_1 = 3240
  • f2=3081f_2 = 3081
  • f3=2841f_3 = 2841
  • f4=343f_4 = 343
  • fi=fi−1⋅223+fi−2⋅229+fi−3⋅fi−4⋅239+17f_i = f_{i-1} \cdot 223 + f_{i-2} \cdot 229 + f_{i-3} \cdot f_{i-4} \cdot 239 + 17 for i>4i > 4

Calculate the sum of (ai+m−1+10)⋅fm(a_{i+m-1} + 10) \cdot f_m over all good subsegments. Since this number can be large, print it modulo 998244353.

Input

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4), the number of test cases. Each test case starts with a line containing two integers nn and kk (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5, 0≤k≤min⁡(n,10)0 \le k \le \min(n, 10)).

The next line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \le a_i \le n).

The sum of nn over all test cases does not exceed 5⋅1055 \cdot 10^5.

Output

For each test case, print a single integer, the answer to the problem.

Examples1

  1. Example 1

    Input
    3
    6 0
    3 1 3 1 3 1
    8 4
    5 8 4 6 5 7 8 5
    7 3
    2 1 3 2 2 1 3
    
    Expected output
    144768
    745933
    448953