1 #include <stdio.h>
2 #include <iostream>
3 #include <algorithm>
4 #include <queue>
5 #include <cstring>
6 #include <cmath>
7
8 using namespace std;
9
10 int main ()
11 {
12 int N;
13 cin >> N;
14 while(N--)
15 {
16 int n,m;
17 cin >> n >> m;
18 queue<int> q;
19 int List[11];
20 memset(List,0,sizeof(List));
21 while(n--)
22 {
23 int tmp;
24 cin >> tmp;
25 if(m == 0)
26 {
27 q.push(-tmp);
28 m --;
29 }
30 else
31 {
32 q.push(tmp);
33 m --;
34 }
35 List[tmp] ++;
36 }
37
38 int time = 0;
39 while(!q.empty())
40 {
41 int i;
42 for(i = abs(q.front())+1;i <= 9;i ++)
43 {
44 if(List[i])
45 {
46 int a = q.front();
47 q.pop();
48 q.push(a);
49 break;
50 }
51 }
52 if(i==10)
53 {
54 List[abs(q.front())] --;
55 if(q.front()<0)
56 {
57 time ++;
58 break;
59 }
60 q.pop();
61 time ++;
62 }
63 // cout << q.front() << " ";
64 }
65 cout << time << endl;
66 }
67 return 0;
68 }