#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long N = 2e5;
long long po(long long, long long);
vector<pair<long long, long long>> v;
long long n, s;
bool check(long long mid) {
  long long sum = 0;
  long long c = 0;
  for (long long i = n - 1; i >= 0; i--) {
    if (mid >= v[i].first && mid <= v[i].second) {
      if (c < n / 2 + 1) {
        sum += mid;
        c++;
      } else {
        sum += v[i].first;
      }
    } else if (mid < v[i].first) {
      if (c < n / 2 + 1) {
        sum += v[i].first;
        c++;
      } else {
        sum += v[i].first;
      }
    } else {
      sum += v[i].first;
    }
  }
  if (c == n / 2 + 1 && sum <= s) {
    return 1;
  } else
    return 0;
}
void solve() {
  cin >> n >> s;
  v.clear();
  for (long long 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 = v[n / 2].first;
  long long r = s + 5;
  while (l < r - 1) {
    long long mid = l + (r - l) / 2;
    if (check(mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  cout << l << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  for (long long i = 1; i < t + 1; i++) {
    solve();
  }
  return 0;
}
long long po(long long a, long long b) {
  if (b == 0) return 1;
  long long ans = 1;
  if (b % 2 == 0) {
    ans = po(a, b / 2) % M;
    ans = (ans % M * ans % M) % M;
  } else {
    ans = po(a, (b - 1) / 2) % M;
    ans = (ans % M * ans % M * a) % M;
  }
  return ans % M;
}
