------
## 最终结论
To solve this problem efficiently given the constraints, we need to avoid checking each number individually in the range [L, R] due to the large possible size of the range (up to 10^18). Instead, we can use a combinatorial approach to count the classy numbers up to a certain number.

Here's the plan:

1. **Define "classy"**: A number is classy if it contains at most 3 non-zero digits.

2. **Counting Classy Numbers**: We can count classy numbers up to a given number by considering:
   - Numbers with 1 non-zero digit.
   - Numbers with 2 non-zero digits.
   - Numbers with 3 non-zero digits.

3. **Use Combinatorics**: For each possible length of a number (in terms of digits), calculate how many combinations of non-zero digits can form such numbers.

4. **Efficient Calculation**:
   - Pre-calculate how many numbers can be formed with a specific number of non-zero digits and total length.
   - Use dynamic programming or memoization to avoid redundant calculations.

5. **Calculate for Each Query**:
   - For each segment [L, R], calculate the number of classy numbers up to R and subtract the number of classy numbers up to L-1.

Here is the Python code implementing this approach:

```python
def count_classy_up_to(n):
    s = str(n)
    length = len(s)
    dp = [[[0] * (4) for _ in range(2)] for _ in range(length + 1)]
    dp[0][0][0] = 1
    
    for i in range(length):
        for smaller in range(2):
            for j in range(4):
                limit = 9 if smaller else int(s[i])
                for digit in range(limit + 1):
                    if digit == 0:
                        dp[i + 1][smaller or (digit < limit)][j] += dp[i][smaller][j]
                    elif j < 3:
                        dp[i + 1][smaller or (digit < limit)][j + 1] += dp[i][smaller][j]

    return sum(dp[length][smaller][j] for smaller in range(2) for j in range(4))

T = int(input())
for _ in range(T):
    L, R = map(int, input().split())
    print(count_classy_up_to(R) - count_classy_up_to(L - 1))
```

### Explanation:

- `count_classy_up_to(n)` calculates how many classy numbers are there from 1 to n.
- `dp[i][smaller][j]` keeps track of how many ways we can form a classy number up to position `i` with `j` non-zero digits and whether we've chosen a smaller digit than `s[i]`.
- For each test case, we compute classy numbers up to `R` and subtract those up to `L-1` to get the count within `[L, R]`. 

This approach efficiently counts classy numbers without iterating over every single number in potentially huge ranges.