#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > v;
vector<long long int> v1;
long long n, s, lef;
bool check(long long x) {
  long long t = lower_bound((v1).begin(), (v1).end(), x) - v1.begin();
  if (t <= n / 2) return 1;
  long long needed = t;
  long long left = lef;
  for (long long i = t - 1; i >= 0; i--) {
    if (needed == n / 2) {
      break;
    }
    if (v[i].second >= x) {
      if ((x - v[i].first) <= left) {
        left -= (x - v[i].first);
        needed--;
      }
    }
  }
  if (needed == n / 2) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    cin >> n >> s;
    long long l = 1000000007, r = -1;
    lef = s;
    v.clear();
    v1.clear();
    for (long long int i = 0; i < n; i++) {
      long long x, y;
      cin >> x >> y;
      lef -= x;
      l = min(l, x);
      r = max(r, y);
      v.push_back({x, y});
      v1.push_back(x);
    }
    sort((v).begin(), (v).end());
    sort((v1).begin(), (v1).end());
    long long ans = v[n / 2].first;
    long long m;
    while (l <= r) {
      m = (l + r) / 2;
      if (check(m)) {
        ans = max(ans, m);
        l = m + 1;
      } else {
        r = m - 1;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
