#include <bits/stdc++.h>
using namespace std;
int takemod(int a, int mod) {
  a %= mod;
  if (a < 0) a += mod;
  return a;
}
int fast_exp(int base, int expo, int mod) {
  int res = 1;
  while (expo > 0) {
    if (expo & 1) res = (res * base) % mod;
    base = (base * base) % mod;
    expo >>= 1;
  }
  return res;
}
int modinv(int a, int mod) {
  return takemod(fast_exp(takemod(a, mod), mod - 2, mod), mod);
}
const long long N = 1e15 + 5, A = 1e5 + 10, md = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n, s;
    cin >> n >> s;
    vector<pair<int, int> > a;
    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      a.push_back(make_pair(x, y));
      s -= x;
    }
    int k = (n + 1) / 2;
    long long l = 1, r = N;
    while (l <= r) {
      long long m = (l + r) / 2;
      vector<long long> b;
      for (int i = 0; i < n; i++) {
        if (a[i].second >= m) {
          b.push_back(a[i].first);
        }
      }
      bool check = 0;
      if (b.size() >= k) {
        sort(b.begin(), b.end());
        long long cost = 0;
        for (int i = 0; i < k; i++) {
          cost += max(0ll, m - b[b.size() - i - 1]);
        }
        if (cost <= s) {
          check = 1;
        }
      }
      if (check) {
        l = m + 1;
      } else {
        r = m - 1;
      }
    }
    cout << l - 1 << endl;
  }
}
