#include <bits/stdc++.h>
using namespace std;
struct num {
  long long l, r;
} a[200005];
bool cmp(num x, num y) {
  if (x.l == y.l) return x.r > y.r;
  return x.l > y.l;
}
long long n, s;
long long check(long long m) {
  long long br = n / 2 + 1, sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i].l <= m && m <= a[i].r && br) {
      br--;
      sum += m;
    } else {
      sum += a[i].l;
      if (a[i].l > m) br--;
    }
  }
  if (br) return s + 1;
  return sum;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    cin >> n >> s;
    for (long long i = 0; i < n; i++) {
      cin >> a[i].l >> a[i].r;
    }
    sort(a, a + n, cmp);
    long long l = a[n / 2].l + 1, r = s;
    while (l <= r) {
      long long m = (l + r) >> 1;
      if (check(m) <= s)
        l = m + 1;
      else
        r = m - 1;
    }
    cout << l - 1 << endl;
  }
}
