#include <bits/stdc++.h>
using namespace std;
int dirx[] = {1, -1, 0, 0}, diry[] = {0, 0, 1, -1};
long long bigmod(long long x, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) res = (res * x) % 998244353;
    x = (x * x) % 998244353;
    p >>= 1;
  }
  return res;
}
vector<pair<int, int> > inp;
int n;
long long fun(int mid) {
  long long sum = mid;
  multiset<int> both;
  int low = 0, high = 0;
  for (int i = 0; i < n; i++) {
    if (inp[i].second > mid) {
      sum += inp[i].second;
      high++;
    } else if (inp[i].first < mid) {
      sum += inp[i].second;
      low++;
    } else
      both.insert(inp[i].second);
  }
  for (int i = 0; i < n / 2 - low; i++) {
    sum += *both.begin();
    both.erase(both.begin());
  }
  sum += 1LL * mid * (n / 2 - high);
  return sum;
}
bool cmp(pair<int, int>& a, pair<int, int>& b) { return a.second < b.second; }
int32_t main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    inp.clear();
    cin >> n;
    long long taka;
    cin >> taka;
    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      inp.push_back({y, x});
    }
    sort(inp.begin(), inp.end());
    int h = inp[n / 2].first, l, mid, ans;
    sort(inp.begin(), inp.end(), cmp);
    l = inp[n / 2].second;
    while (l <= h) {
      int mid = (l + h) / 2;
      if (fun(mid) <= taka) {
        ans = mid;
        l = mid + 1;
      } else
        h = mid - 1;
    }
    cout << ans << "\n";
  }
  return 0;
}
