#include <bits/stdc++.h>
using namespace std;
int n;
long long s;
long long l[200010], r[200010], b[200010];
long long res;
bool ok(long long x) {
  long long tmp = 0;
  int dem;
  dem = 0;
  vector<int> mi;
  mi.clear();
  for (int i = 1; i <= n; i++) {
    if (r[i] < x) {
      tmp += l[i];
      continue;
    }
    if (l[i] > x) {
      tmp += l[i];
      dem++;
      continue;
    }
    tmp += x;
    dem++;
    mi.push_back(l[i]);
  }
  if (dem < n / 2 + 1) return false;
  sort(mi.begin(), mi.end());
  int now = 0;
  while (dem > n / 2 + 1) {
    if (now >= mi.size()) return false;
    tmp += (mi[now] - x);
    now++;
    dem--;
  }
  return (tmp <= s);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int ntest;
  cin >> ntest;
  for (int test = 1; test <= ntest; test++) {
    cin >> n >> s;
    for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];
    for (int i = 1; i <= n; i++) b[i] = l[i];
    sort(b + 1, b + n + 1);
    long long lo, hi, mid;
    lo = b[n / 2 + 1];
    hi = 1000000100;
    while (lo <= hi) {
      mid = (lo + hi) >> 1;
      if (ok(mid)) {
        res = mid;
        lo = mid + 1;
      } else
        hi = mid - 1;
    }
    cout << res << endl;
  }
}
