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 static java.util.Arrays.asList;
  
  import java.io.BufferedReader;
  import java.io.ByteArrayOutputStream;
  import java.io.Closeable;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.PrintStream;
  import java.net.URISyntaxException;
  import java.nio.file.Files;
  import java.nio.file.Path;
  import java.nio.file.Paths;
  import java.util.List;
  import java.util.StringTokenizer;
  import java.util.function.Supplier;
  
  /**
   * A. The Miracle and the Sleeper
   * @see <a href="https://codeforces.com/contest/1562/problem/A">https://codeforces.com/contest/1562/problem/A</a>
   */
  public class Main {
  
      private final boolean sample;
      private final InputStream in;
      private final PrintStream out;
      
      public Main(
              final Boolean sample, final InputStream in, final PrintStream out) {
          this.sample = sample;
          this.in = in;
          this.out = out;
      }
      
      @SuppressWarnings("unused")
      private void log(final Supplier<Object> supplier) {
          if (!sample) {
              return;
          }
          System.out.println(supplier.get());
      }
      
      private void handleTestCase(final Integer i, final FastScanner sc) {
          final int l = sc.nextInt();
          final int r = sc.nextInt();
          if (r < 2 * l) {
              this.out.println(r - l);
          } else {
              this.out.println((r - 1) / 2);
          }
      }
      
      public void solve() {
          try (final FastScanner sc = new FastScanner(this.in)) {
              final int numberOfTestCases = sc.nextInt();
              for (int i = 0; i < numberOfTestCases; i++) {
                  handleTestCase(i, sc);
              }
          }
      }
  
      public static void main(final String[] args) throws IOException, URISyntaxException {
          final boolean sample = isSample();
          final InputStream is;
          final PrintStream out;
          final ByteArrayOutputStream baos = new ByteArrayOutputStream();
          long timerStart = 0;
          if (sample) {
              is = Main.class.getResourceAsStream("sample.in");
              out = new PrintStream(baos, true);
              timerStart = System.nanoTime();
          } else {
              is = System.in;
              out = System.out;
          }
          
          new Main(sample, is, out).solve();
          
          out.flush();
          if (sample) {
              final long timeSpent = (System.nanoTime() - timerStart) / 1_000;
              final double time;
              final String unit;
              if (timeSpent < 1_000) {
                  time = timeSpent;
                  unit = "µs";
              } else if (timeSpent < 1_000_000) {
                  time = timeSpent / 1_000.0;
                  unit = "ms";
              } else {
                  time = timeSpent / 1_000_000.0;
                  unit = "s";
              }
              final Path path
                      = Paths.get(Main.class.getResource("sample.out").toURI());
              final List<String> expected = Files.readAllLines(path);
              final List<String> actual = asList(baos.toString().split("\\r?\\n"));
              if (!expected.equals(actual)) {
                  throw new AssertionError(String.format(
                          "Expected %s, got %s", expected, actual));
              }
              actual.forEach(System.out::println);
              System.out.println(String.format("took: %.3f %s", time, unit));
          }
      }
      
      private static boolean isSample() {
          try {
              return "sample".equals(System.getProperty("codeforces"));
          } catch (final SecurityException e) {
              return false;
          }
      }
      
      private static final class FastScanner implements Closeable {
          private final BufferedReader br;
          private StringTokenizer st;
          
          public FastScanner(final InputStream in) {
              this.br = new BufferedReader(new InputStreamReader(in));
              st = new StringTokenizer("");
          }
          
          public String next() {
              while (!st.hasMoreTokens()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (final IOException e) {
                      throw new RuntimeException(e);
                  }
              }
              return st.nextToken();
          }
      
          public int nextInt() {
              return Integer.parseInt(next());
          }
          
          @SuppressWarnings("unused")
          public int[] nextIntArray(final int n) {
              final int[] a = new int[n];
              for (int i = 0; i < n; i++) {
                  a[i] = nextInt();
              }
              return a;
          }
          
          @SuppressWarnings("unused")
          public long nextLong() {
              return Long.parseLong(next());
          }
  
          @Override
          public void close() {
              try {
                  this.br.close();
              } catch (final IOException e) {
                  // ignore
              }
          }
      }
  }
  