description: You are given two integers l and r, l≤ r. Find the largest possible value of a mod b over all pairs (a, b) of integers for which r≥ a ≥ b ≥ l.
  
  As a reminder, a mod b is a remainder we get when dividing a by b. For example, 26 mod 8 = 2.
  
  Input
  
  Each test contains multiple test cases.
  
  The first line contains one positive integer t (1≤ t≤ 10^4), denoting the number of test cases. Description of the test cases follows.
  
  The only line of each test case contains two integers l, r (1≤ l ≤ r ≤ 10^9).
  
  Output
  
  For every test case, output the largest possible value of a mod b over all pairs (a, b) of integers for which r≥ a ≥ b ≥ l.
  
  Example
  
  Input
  
  
  4
  1 1
  999999999 1000000000
  8 26
  1 999999999
  
  
  Output
  
  
  0
  1
  12
  499999999
  
  Note
  
  In the first test case, the only allowed pair is (a, b) = (1, 1), for which a mod b = 1 mod 1 = 0.
  
  In the second test case, the optimal choice is pair (a, b) = (1000000000, 999999999), for which a mod b = 1.
solution: import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.math.BigInteger;
  import java.util.*;
  
  public class Practice {
  //	public static long mod = (long) Math.pow(10, 9) + 7;
  //	public static long mod2 = 998244353;
  //	public static int tt = 1;
  //	public static ArrayList<Integer> prime;
  //	public static long[] fac = new long[200005];
  //	public static long[] invfac = new long[200005];
  
  	public static void main(String[] args) throws Exception {
  		PrintWriter pw = new PrintWriter(System.out);
  		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  		int t = Integer.parseInt(br.readLine());
  		while (t-- > 0) {
  			String[] s1 = br.readLine().split(" ");
  			int n = Integer.valueOf(s1[0]);
  			int m = Integer.valueOf(s1[1]);
  			int x = m / 2 + 1;
  			int sec = Math.max(x, n);
  			pw.println(m - sec);
  		}
  		pw.close();
  	}
  
  //
  //	private static long power(long a, long p) {
  //		// TODO Auto-generated method stub
  //		long res = 1;
  //		while (p > 0) {
  //			if (p % 2 == 1) {
  //				res = (res * a) % mod;
  //			}
  //			p = p / 2;
  //			a = (a * a) % mod;
  //		}
  //		return res;
  //	}
  
  	// private static int kmp(String str) {
  //		// TODO Auto-generated method stub
  //		// System.out.println(str);
  //		int[] pi = new int[str.length()];
  //		pi[0] = 0;
  //		for (int i = 1; i < str.length(); i++) {
  //			int j = pi[i - 1];
  //			while (j > 0 && str.charAt(i) != str.charAt(j)) {
  //				j = pi[j - 1];
  //			}
  //			if (str.charAt(j) == str.charAt(i)) {
  //				j++;
  //			}
  //			pi[i] = j;
  //			System.out.print(pi[i]);
  //		}
  //		System.out.println();
  //		return pi[str.length() - 1];
  //	}
  
  }
  
  //	private static void getFac(long n, PrintWriter pw) {
  //		// TODO Auto-generated method stub
  //		int a = 0;
  //		while (n % 2 == 0) {
  //			a++;
  //			n = n / 2;
  //		}
  //		if (n == 1) {
  //			a--;
  //		}
  //		for (int i = 3; i <= Math.sqrt(n); i += 2) {
  //			while (n % i == 0) {
  //				n = n / i;
  //				a++;
  //			}
  //		}
  //		if (n > 1) {
  //			a++;
  //		}
  //		if (a % 2 == 0) {
  //			pw.println("Bob");
  //		} else {
  //			pw.println("Alice");
  //		}
  //		//System.out.println(a);
  //		return;
  //	}
  
  //	private static long power(long a, long p) {
  //		// TODO Auto-generated method stub
  //		long res = 1;
  //		while (p > 0) {
  //			if (p % 2 == 1) {
  //				res = (res * a) % mod;
  //			}
  //			p = p / 2;
  //			a = (a * a) % mod;
  //		}
  //		return res;
  //	}
  //
  //	private static void fac() {
  //		fac[0] = 1;
  //		// TODO Auto-generated method stub
  //		for (int i = 1; i < fac.length; i++) {
  //			if (i == 1) {
  //				fac[i] = 1;
  //			} else {
  //				fac[i] = i * fac[i - 1];
  //			}
  //			if (fac[i] > mod) {
  //				fac[i] = fac[i] % mod;
  //			}
  //		}
  //	}
  //
  //	private static int getLower(Long long1, Long[] st) {
  //		// TODO Auto-generated method stub
  //		int left = 0, right = st.length - 1;
  //		int ans = -1;
  //		while (left <= right) {
  //			int mid = (left + right) / 2;
  //			if (st[mid] <= long1) {
  //				ans = mid;
  //				left = mid + 1;
  //			} else {
  //				right = mid - 1;
  //			}
  //		}
  //		return ans;
  //	}
  
  //private static long getGCD(long l, long m) {
  //
  //	long t1 = Math.min(l, m);
  //	long t2 = Math.max(l, m);
  //	if (t1 == 0) {
  //		return t2;
  //	}
  //	while (true) {
  //		long temp = t2 % t1;
  //		if (temp == 0) {
  //			return t1;
  //		}
  //		t2 = t1;
  //		t1 = temp;
  //	}
  //}