#include <bits/stdc++.h>
using namespace std;
int n;
long long s;
vector<array<int, 2>> v(200001);
bool check(int x) {
  int cnt = n / 2 + 1;
  long long res = 0;
  for (int i = n - 1; i > -1 && res <= s; i--) {
    if (cnt && v[i][1] >= x) {
      res += max(x, v[i][0]);
      cnt--;
    } else
      res += v[i][0];
  }
  return (res <= s && cnt == 0);
}
void solve() {
  cin >> n >> s;
  v.resize(n);
  for (int i = 0; i < n; i++) cin >> v[i][0] >> v[i][1];
  sort(v.begin(), v.end());
  int l = 0, r = 1e9 + 5, mid, ans = 1;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) solve();
}
