378 传统题

[CF2289B] 固定子序列位置计数 (Problem from Chebarkul)

时间限制
1000ms
内存限制
256MiB
登顶 / 尝试
0/ 0
难度
3

[CF2289B] 固定子序列位置计数 (Problem from Chebarkul)

Problem Statement

You are given an array of integers a1,a2,…,ana_1, a_2, \dots, a_n and an integer kk.

Find the number of integers 1≤i≤k1 \le i \le k such that in all subsequences of the array aa of length kk, the same number is located at the ii-th position.

Input

The first line contains tt (1≤t≤1041 \le t \le 10^4). Each test case has n,kn, k (1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5), followed by a1,…,ana_1, \dots, a_n (1≤ai≤n1 \le a_i \le n). Sum of nn over all test cases ≤2⋅105\le 2 \cdot 10^5.

Output

For each test case, output one integer — the number of positions with a fixed value across all length-kk subsequences.

样例

7
1 1
1
3 1
2 2 3
4 2
1 1 1 1
4 2
1 2 1 2
4 4
4 1 4 2
5 3
1 2 2 2 5
6 5
1 1 2 2 1 1
1
0
2
0
4
1
3