#include <bits/stdc++.h>
using namespace std;
long long t, n, s, l, r, mid, sum, ans, answer;
pair<long long, long long> p[200005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (int rr = 0; rr < t; rr++) {
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
      cin >> p[i].first >> p[i].second;
    }
    sort(p, p + n);
    l = 1;
    r = s;
    while (l <= r) {
      mid = (l + r) >> 1;
      sum = (n + 1) >> 1;
      ans = 0;
      for (int i = n - 1; i >= 0; i--) {
        if (p[i].first <= mid && p[i].second >= mid && sum > 0) {
          sum--;
          ans += mid;
        } else if (p[i].first > mid) {
          sum--;
          ans += p[i].first;
        } else {
          ans += p[i].first;
        }
      }
      if (ans > s || sum > 0) {
        r = mid - 1;
      } else {
        l = mid + 1;
        answer = mid;
      }
    }
    cout << answer << '\n';
  }
}
