World Fragments III
时间限制:C/C++/Rust/Pascal 5秒,其他语言10秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
Special Judge, 64bit IO Format: %lld

题目描述

This problem is different from World Fragments I and World Fragments II. Please read the statements carefully.

There are q queries for you to answer.

For each query, you are given two non-negative decimal integers x and y without leading zeros. You can apply the following operation to x any number of times (possibly zero):

  1. Choose a digit b in x.

  2. Let either x \gets x + b or x \gets x - b.

For example, when x = (616)_{10} you can choose the digit b=(1)_{10} in (6\underline{1}6)_{10}, then let x \gets x - b = (616)_{10} - (1)_{10} = (615)_{10}.

Find out the least number of operations needed to turn x into y. Since the answer can be very large, output it modulo 998\,244\,353. Print -1 if it is impossible to turn x into y.

输入描述:

The first line contains a positive integer T (1\leq T\leq 10^3) — the number of queries.

Each query consists of a line that contains two integers x, y (0\leq x\le y\leq 10^{10^{6}}). Please note that in this version, x\le y.

It is guaranteed that the sum of the lengths of the decimal representations of all ys does not exceed 2\times10^{6}.

输出描述:

For each query, print a decimal integer in a single line, denoting the answer modulo 998\,244\,353. If it is impossible to turn x into y, print -1.

示例1

输入

复制
4
1 7
1 9
13 23
123456789 987654321

输出

复制
-1
6
8
102755278

备注:

The operations in the third example are:

1\underline{3}\to1\underline{6}\to2\underline{2}\to2\underline{4}\to2\underline{8}\to \underline{3}0\to\underline{2}7\to\underline{2}5\to23.