/**
 *    author:  tourist
 *    created: 21.10.2026 10:13:23
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    int64_t p;
    cin >> n >> p;
    vector<int64_t> j(n), t(n);
    for (int i = 0; i < n; i++) {
      cin >> j[i] >> t[i];
    }
    int ans = -1;
    int64_t mx = -1;
    int occ = 0;
    for (int i = 0; i < n; i++) {
      if (i < n - 1) {
        if (occ == 1 && mx > j[n - 1] + p) {
          ans = i;
          break;
        }
        if (max(mx, j[n - 2] + p) < j[n - 1]) {
          ans = i;
          break;
        }
      }
      j[i] += t[i];
      p -= t[i];
      t[i] = 0;
      if (j[i] > mx) {
        mx = j[i];
        occ = 0;
      }
      if (j[i] == mx) {
        occ += 1;
      }
    }
    if (occ == 1 && ans == -1) {
      ans = n - 1;
    }
    cout << ans << '\n';
  }
  return 0;
}
