/* for l = 8, r = 26 */
include
include
include
include
using namespace std; using L = long; using LL = long long;
int main() {
int t; cin >> t; while (t--) { LL l, r; cin >> l >> r; LL res = (r >= 2 * l) ? (r - 1) / 2 : (r - l); cout << res << endl; } return 0;
} /* how it is so that the answer is not 18 but 12!??? thanks, */