#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
struct Node {
  int L, R;
  bool operator<(const Node &other) const { return L < other.L; }
};
int N, H;
long long S;
vector<Node> v;
bool possible(int median) {
  long long sum = 0;
  for (Node &s : v) sum += s.L;
  int count = 0;
  for (int i = N - 1; i >= 0 && count < H; i--)
    if (v[i].R >= median) {
      sum += max(median - v[i].L, 0);
      count++;
    }
  return count == H && sum <= S;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> N >> S;
    H = (N + 1) / 2;
    v.resize(N);
    for (Node &s : v) cin >> s.L >> s.R;
    sort(v.begin(), v.end());
    int l = 0, r = INF, ans;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (possible(mid)) {
        ans = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    cout << ans << '\n';
  }
  return 0;
}
