#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  long long int k;
  cin >> n >> k;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(), a.end());
  int ans = -1;
  long long int l = 0, r = 2e9;
  for (int i = 0; i < 60; i++) {
    long long int m = l + (r - l) / 2;
    int less = 0, right = 0, center = 0;
    long long int money = 0;
    vector<int> c;
    for (auto &e : a) {
      if (e.second < m) {
        money += e.first;
      } else if (e.first >= m) {
        money += e.first;
        right++;
      } else if (e.first < m && m <= e.second) {
        c.push_back(e.first);
      }
    }
    int need = max(0, (n + 1) / 2 - right);
    if (need > c.size()) {
      r = m - 1;
    } else {
      for (int i = 0; i < c.size(); i++) {
        if (i < c.size() - need)
          money += c[i];
        else
          money += m;
      }
      if (money <= k) {
        ans = m;
        l = m + 1;
      } else {
        r = m - 1;
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
