#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int N;
int l[maxn], r[maxn];
long long s;
int check(int x) {
  int must_g = 0, must_s = 0;
  long long sum = 0;
  vector<int> num;
  for (int i = 1; i <= N; i++) {
    if (r[i] < x)
      must_s++, sum += l[i];
    else if (l[i] > x)
      must_g++, sum += l[i];
    else if (l[i] <= x && r[i] >= x)
      num.push_back(l[i]);
  }
  if (must_g > (N - 1) / 2) return 1;
  if (must_s > (N - 1) / 2) return 0;
  sort(num.begin(), num.end());
  int remain = (N - 1) / 2 - must_s;
  for (int i = 0; i <= remain - 1; i++) sum += num[i];
  remain = (N - 1) / 2 - must_g + 1;
  sum += (long long)remain * (long long)x;
  return sum <= s;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> N >> s;
    for (int i = 1; i <= N; i++) cin >> l[i] >> r[i];
    int lll = 1, rrr = 1e9, ans = 0;
    while (lll <= rrr) {
      int mid = (lll + rrr) >> 1;
      if (check(mid)) {
        lll = mid + 1;
        ans = max(ans, mid);
      } else
        rrr = mid - 1;
    }
    cout << ans << "\n";
  }
  return 0;
}
