#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
const long long INF = 1e9;
const long long MOD = INF + 7;
long long n, s;
vector<pair<long long, long long> > a;
bool solve(long long m) {
  long long idx = (long long)n / 2;
  long long sm = 0;
  for (long long i = 0; i < n; i++) {
    sm += a[i].first;
  }
  long long cnt = 0;
  for (long long i = n - 1; i >= 0 && cnt <= idx; i--) {
    if (m <= a[i].second) {
      sm += max(0LL, m - a[i].first);
      cnt++;
    }
  }
  return cnt == idx + 1 && sm <= s;
}
void solve() {
  cin >> n >> s;
  a.clear();
  long long sm = 0;
  for (long long i = 0, x, y; i < n; i++) {
    cin >> x >> y;
    a.push_back({x, y});
    sm += x;
  }
  sort((a).begin(), (a).end());
  long long lo = 0, hi = INF * INF;
  while (lo < hi) {
    long long now = sm;
    long long m = (lo + hi + 1) / 2;
    if (solve(m))
      lo = m;
    else
      hi = m - 1;
  }
  cout << lo << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
