#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int targetc = 3; int ten[100]; vector to; void tr(int c, int pr, int tot) { if (c == targetc) { to.push_back(tot); return; } for (int i = 1; i <= 9; i++) { if (i % pr == 0) { tr(c+1, i, tot+i * ten[c]); } } } int main() { to.clear(); ten[0] = 1; for (int i = 1; i < 100; i++) ten[i] = ten[i-1] * 10; for (int c = 1; c <= 9; c++) { targetc = c; for (int i = 1; i <= 9; i++) { tr(1, i, i); } } sort(to.begin(), to.end()); int ff; scanf("%d", &ff); while (ff--) { int l, r; scanf("%d %d", &l, &r); printf("%d\n", upper_bound(to.begin(), to.end(), r) - lower_bound(to.begin(), to.end(), l)); } }