#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
bool prime[1000001];
long long spf[10000001];
long long f[300005];
long long pow1(long long x, long long y) {
  long long res = 1;
  x = x % mod;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
long long divide(long long n) { return pow1(n, mod - 2); }
long long ncr(long long n, long long r) {
  if (n < r) return 0;
  return (f[n] * ((divide(f[r]) * divide(f[n - r])) % mod)) % mod;
}
void sieve() {
  memset(prime, true, sizeof(prime));
  for (long long i = 2; i * i <= 1000000; i++)
    if (prime[i])
      for (long long j = i * i; j <= 1000000; j += i) prime[j] = false;
  prime[0] = prime[1] = false;
}
void fastsieve() {
  spf[1] = 1;
  for (int i = 2; i <= 1e7; i++) spf[i] = i;
  for (int i = 4; i <= 1e7; i += 2) spf[i] = 2;
  for (int i = 3; i * i <= 1e7; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j <= 1e7; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
vector<long long> factorize(long long n) {
  long long count = 0;
  vector<long long> fac;
  while (!(n % 2)) {
    n >>= 1;
    count++;
  }
  if (count % 2) fac.push_back(2ll);
  for (long long i = 3; i <= sqrt(n); i += 2) {
    count = 0;
    while (n % i == 0) {
      count++;
      n = n / i;
    }
    if (count % 2) fac.push_back(i);
  }
  if (n > 2) fac.push_back(n);
  return fac;
}
vector<long long> fastfactorize(long long n) {
  vector<long long> v;
  long long prev = 0, cnt = 0;
  while (n != 1) {
    if (prev == spf[n])
      cnt++;
    else {
      if (cnt % 2) v.push_back(prev);
      cnt = 1;
      prev = spf[n];
    }
    n /= spf[n];
    if (n == 1) {
      if (cnt % 2) v.push_back(prev);
      cnt = 1;
      prev = spf[n];
    }
  }
  return v;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, s, i, ans = 0;
    cin >> n >> s;
    vector<pair<long long, long long>> v;
    for (i = 0; i < n; i++) {
      long long l, r;
      cin >> l >> r;
      v.push_back({l, r});
    }
    sort(v.begin(), v.end());
    long long l = 0, r = 1e9 + 1;
    while (l <= r) {
      long long mid = (l + r) / 2, cnt = 0, sum = 0;
      for (i = n - 1; i >= 0; i--) {
        if (mid <= v[i].second && cnt < (n + 1) / 2) {
          cnt++;
          sum += max(mid, v[i].first);
        } else
          sum += v[i].first;
      }
      if (cnt < (n + 1) / 2 || sum > s)
        r = mid - 1;
      else
        l = mid + 1, ans = mid;
    }
    cout << ans << endl;
  }
  return 0;
}
