#include <bits/stdc++.h>
using namespace std;
void optimise() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
bool compare(pair<long long int, long long int> X,
             pair<long long int, long long int> Y) {
  if (X.second < Y.second)
    return 1;
  else if (Y.second < X.second)
    return 0;
  else {
    if (X.first <= Y.first)
      return 1;
    else
      return 0;
  }
}
void solve() {
  long long int n, s;
  cin >> n >> s;
  vector<pair<long long int, long long int> > v(n);
  for (long long int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.rbegin(), v.rend());
  long long int beg = 1;
  long long int end = s;
  long long int ans = -1;
  while (beg <= end) {
    long long int mid = (beg + end) / 2;
    long long int sum = 0;
    long long int curr = 0;
    long long int flag = 0;
    for (long long int i = 0; i < n; i++) {
      if ((v[i].first >= mid || (v[i].first <= mid && v[i].second >= mid)) &&
          (curr < (n + 1) / 2)) {
        sum += max(v[i].first, mid);
        curr++;
      } else
        sum += v[i].first;
    }
    if (curr == (n + 1) / 2 && sum <= s) {
      beg = mid + 1;
      ans = mid;
    } else
      end = mid - 1;
  }
  cout << ans;
}
signed main() {
  optimise();
  long long int t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
}
