#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
const long long mas = 200000 + 10;
long long l[mas], r[mas];
long long num[mas];
bool cmp(int x, int y) { return l[x] < l[y]; }
int main() {
  fast();
  long long t;
  cin >> t;
  long long n, s, kol, mn, mx, h, tmp;
  while (t--) {
    cin >> n >> s;
    for (int i = 1; i <= n; ++i) cin >> l[i] >> r[i];
    for (int i = 1; i <= n; ++i) num[i] = i;
    sort(num + 1, num + n + 1, cmp);
    for (int i = 1; i <= n; ++i) s -= l[i];
    mn = 1;
    mx = 10000000000;
    while (mn + 1 < mx) {
      kol = 0;
      h = (mx + mn) / 2;
      for (int i = 1; i <= n; ++i) {
        if (r[i] >= h) kol++;
      }
      if (kol <= n / 2) {
        mx = h;
        continue;
      }
      kol = 0;
      for (int i = n; i >= 1; --i) {
        if (r[num[i]] >= h) kol++;
        if (kol == n / 2 + 1) {
          kol = i;
          break;
        }
      }
      tmp = s;
      for (int i = n; i >= kol; --i) {
        if (r[num[i]] >= h && l[num[i]] < h) {
          tmp -= h - l[num[i]];
        }
      }
      if (tmp >= 0) {
        mn = h;
      } else {
        mx = h;
      }
    }
    cout << mn << "\n";
  }
  return 0;
}
