1 #include<iostream>
2 #include<string>
3 #include<queue>
4 #include<stack>
5 #include<vector>
6 #include<map>
7 #include<cstdio>
8 #include<cstdlib>
9 #include<algorithm>
10 #include<set>
11 #include<list>
12 #include<iomanip>
13 #include<cstring>
14 #include<cmath>
15 #include<limits>
16 using namespace std;
17
18 #define au auto
19 #define debug(i) cout<<"<debug> "<<i<<" <\debug>"<<endl
20 #define mfor(i,a,b) for(register int i=(a);i<=(b);i++)
21 #define mrep(i,a,b) for(register int i=(a);i>=(b);i--)
22 #define LLL __int128
23 #define Re register
24 #define il inline
25 #define mem(a,b) memset(a,(b),sizeof(a))
26 typedef pair<int, int> intpair;
27 typedef pair<long long int, long long int> llpair;
28 typedef long long int LL;
29 const int INF = 0x3f3f3f3f;
30 const long long int INFLL = 0x3f3f3f3f3f3f3f3f;
31
32 const int maxn = 1000010;
33
34 LL n;
35 LL s;
36 LL ans;
37 int T;
38 llpair a[maxn];
39
40 bool operator >(llpair a, llpair b)
41 {
42 return a.first > b.first;
43 }
44
45 bool check(LL x)
46 {
47 LL t = (n >> 1) + 1; //需要满足有t个工资大于等于x
48 LL sum = 0;
49 mfor(i, 1, n)
50 {
51 if (t && a[i].first <= x && x <= a[i].second)
52 {
53 //这个工人可以被发x的工资
54 //贪心策略,一律取等于
55 sum += x;
56 t--;
57 }
58 else
59 {
60 //贪心策略,不能被发x的工资,那就给他发能给的最少工资
61 sum += a[i].first;
62 if (a[i].first >= x && t) t--;//如果这个最少工资比x大
63 }
64 }
65 if (t) return 0; //不满足条件,x不能是中位数
66 return sum <= s; //判断钱是否足够
67 }
68
69 int main()
70 {
71 ios::sync_with_stdio(0);
72 cin.tie(0);
73 cout.tie(0);
74 cin >> T;
75 while (T--)
76 {
77 ans = 0;
78 cin >> n >> s;
79 mfor(i, 1, n) cin >> a[i].first >> a[i].second;
80 sort(a + 1, a + n + 1, greater<llpair>());
81 LL l = a[(n >> 1) + 1].first, r = s;
82 ans = a[(n >> 1) + 1].first;
83 while (l <= r)
84 {
85 LL mid = (l + r) >> 1;
86 if (check(mid))
87 {
88 ans = mid;
89 l = mid + 1;
90 }
91 else r = mid - 1;
92 }
93 cout << ans << endl;
94 }
95 return 0;
96 }