#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)(1e9 + 7);
const long long N = 200007;
vector<pair<long long, long long>> v;
long long s;
int n;
int sure(long long median) {
  long long cnt1 = 0;
  long long cnt2 = 0;
  long long cnt3 = 0;
  long long sum = 0;
  vector<long long> tmp;
  for (auto ele : v) {
    long long l = ele.first;
    long long r = ele.second;
    if (r < median) {
      cnt1 += 1;
      sum += l;
    } else if (l > median) {
      cnt3 += 1;
      sum += l;
    } else {
      cnt2 += 1;
      tmp.push_back(l);
    }
  }
  long long mn = (n - 1) / 2;
  if (cnt1 > mn) {
    return 0;
  } else if (cnt3 > mn) {
    return 1;
  }
  int idx = 0;
  while (cnt1 < mn) {
    cnt1 += 1;
    sum += tmp[idx];
    idx += 1;
  }
  for (int i = idx; i < tmp.size(); i++) {
    sum += median;
  }
  if (sum > s) {
    return 0;
  } else {
    return 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int tt;
  cin >> tt;
  for (int t = 1; t <= tt; t++) {
    v.clear();
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
      long long x, y;
      cin >> x >> y;
      v.push_back({x, y});
    }
    sort(v.begin(), v.end());
    long long l = 1;
    long long r = MOD;
    long long ans = 0;
    while (l <= r) {
      long long mid = (l + r) / 2;
      if (sure(mid) == 1) {
        ans = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
