#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef double DB; typedef pair PII; typedef vector VI; typedef vector VPII; #define X first #define Y second #define pb push_back #define bit(n) (1 << (n)) #define count(n) (__builtin_popcount(n)) #define countl(n) (__builtin_popcountll(n)) template inline void chkmin(T &x, T y) { if (y < x) x = y; } template inline void chkmax(T &x, T y) { if (x < y) x = y; } const int MN = 100005; const int MOD = int(1e9 + 7); int cnt[MN][20]; char a[MN], b[MN]; int calc(char *s) { int n = strlen(s), i; int ans[20]; memset(ans, 0, sizeof ans); i = 0; while (s[i] == '0') i++; int x = 0; for (; i < n; i++) { int t = s[i] - '0'; for (int j = 0; j < t; j++) { for (int k = 0; k < 16; k++) { ans[x ^ j ^ k] = (ans[x ^ j ^ k] + cnt[n - i - 1][k]) % MOD; } } x ^= t; } int rlt = 0; for (int i = 0; i < 16; i++) rlt = (rlt + 1LL * i * ans[i]) % MOD; return (rlt + x) % MOD; } int main() { int tn; cnt[0][0] = 1; for (int i = 0; i < 10; i++) cnt[1][i] = 1; for (int i = 2; i < MN; i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 16; k++) { cnt[i][j ^ k] = (cnt[i][j ^ k] + cnt[i - 1][k]) % MOD; } } } int T(0); for (cin >> tn; tn--; ) { scanf("%s%s", &a, &b); int x = 0; for (int i = 0; a[i]; i++) x ^= a[i] - '0'; printf("Case #%d: %d\n", ++T, (calc(b) - calc(a) + MOD + x) % MOD); } return 0; }