#include "bits/stdc++.h" using namespace std; using ll = long long; #define test ll cases; cin>>cases; for(ll testCase = 1; testCase <= cases; testCase++) string l, r; ll dp[20][2][2][2][1 << 11]; ll calc(ll i, ll tightL, ll tightR, ll started, ll mask) { // !mask = TRUE when mask = 0 => all even frequency if(i == l.size()) return !mask; if(dp[i][tightL][tightR][started][mask] != -1) return dp[i][tightL][tightR][started][mask]; // instead of separately calculating everything for L and R, we can use ll low = tightL ? l[i] - '0' : 0; ll high = tightR ? r[i] - '0' : 9; ll ans = 0; for(ll digit = low; digit <= high; digit++) { ll nextStarted = started | (digit > 0); ans += calc(i+1, tightL & (digit == low), tightR & (digit == high), nextStarted, nextStarted ? mask ^ (1 << digit) : mask); } return dp[i][tightL][tightR][started][mask] = ans; } int main(){ test{ cin >> l >> r; // Make the numbers of equal number of digits while(l.size() != r.size()) l = "0" + l; memset(dp, -1, sizeof(dp)); cout << calc(0, 1, 1, 0, 0) << endl; } }