#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    ll n, s;
    cin >> n >> s;
    vector<array<int, 2>> ranges(n);
    for (int i = 0; i < n; i++) {
      cin >> ranges[i][0] >> ranges[i][1];
    }
    int l = 0, r = 1e9 + 1;
    auto check = [&](ll x) {
      int ok = 1;
      int rlessmid = 0, lgreatemid = 0;
      ll curs = s;
      vector<int> l;
      for (int i = 0; i < n; i++) {
        if (ranges[i][1] < x)
          rlessmid++, curs -= ranges[i][0];
        else if (ranges[i][0] >= x)
          lgreatemid++, curs -= ranges[i][0];
        else {
          l.push_back(ranges[i][0]);
        }
      }
      if (rlessmid > n / 2) return 0;
      if (lgreatemid > n / 2) return 1;
      sort(l.begin(), l.end());
      int need = n / 2 - rlessmid;
      for (int j = 0; j < need; j++) {
        curs -= l[j];
      }
      if (curs >= x * (l.size() - need)) return 1;
      return 0;
    };
    while (r - l > 1) {
      int mid = l + (r - l) / 2;
      if (check(mid))
        l = mid;
      else
        r = mid;
    }
    cout << l << endl;
  }
  return 0;
}
