#include <bits/stdc++.h>
using namespace std;
#define ll long long
void mayTheForceBeWithYou(){
int p, seats;
cin >> p >> seats;
vector<int> a(p);
int countl = 0;
int countr = 0;
set<int> x;
for(int i = 0; i<p; i++){
cin >> a[i];
if(a[i] == -1) countl++;
else if(a[i] == -2) countr++;
else x.insert(a[i]);
}
int s = x.size();
int j = 0;
//ignore one type
int ans = min(seats, max(countl + s, countr + s));
//element number j is the pivot point = p
for (int p : x) {
int lf = min(countl + j, p - 1), rf = min(seats - p + 1, countr + s - j);
ans = max(ans, lf + rf);
j++;
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int ts = 1;
cin>>ts;
while (ts--){
mayTheForceBeWithYou();
cout<<endl;
}
}
264A - Escape from Stones | 1506A - Strange Table |
456A - Laptops | 855B - Marvolo Gaunt's Ring |
1454A - Special Permutation | 1359A - Berland Poker |
459A - Pashmak and Garden | 1327B - Princesses and Princes |
1450F - The Struggling Contestant | 1399B - Gifts Fixing |
1138A - Sushi for Two | 982C - Cut 'em all |
931A - Friends Meeting | 1594A - Consecutive Sum Riddle |
1466A - Bovine Dilemma | 454A - Little Pony and Crystal Mine |
2A - Winner | 1622B - Berland Music |
1139B - Chocolates | 1371A - Magical Sticks |
1253A - Single Push | 706B - Interesting drink |
1265A - Beautiful String | 214A - System of Equations |
287A - IQ Test | 1108A - Two distinct points |
1064A - Make a triangle | 1245C - Constanze's Machine |
1005A - Tanya and Stairways | 1663F - In Every Generation |