#include #include using namespace std; int N, D[100100]; long long L[100100], R[100100], B[77], BB[77]; const int mod = 1000000007; int main() { B[0] = 10; BB[0] = 1; for (int i = 1; i < 70; i++){ B[i] = B[i - 1] * B[i - 1] % mod; BB[i] = BB[i - 1] * (B[i - 1] + 1) % mod; } scanf ("%d", &N); for (int i = 0; i < N; i++) scanf ("%lld", &L[i]); for (int i = 0; i < N; i++) scanf ("%lld", &R[i]); for (int i = 0; i < N; i++) scanf ("%d", &D[i]); int s = 0; while (s < N && D[s] == 0) s++; for (int i = s; i < N; i++) if (D[i] == 0){ puts("0"); return 0; } for (int i = s; i < N; i++){ L[i - s] = L[i]; R[i - s] = R[i]; D[i - s] = D[i]; } N -= s; long long ans = 1; int ld = 0; for (int i = 0; i < N; i++){ int nd = (D[i] + 9 - ld) % 9; int p = 0; long long upp = R[i] - L[i]; for (int b = 0; upp; b++){ if (upp & 1) p = (B[b] * p + BB[b]) % mod; upp /= 2; } long long low = L[i]; for (int b = 0; low; b++){ if (low & 1) p = B[b] * p % mod; low /= 2; } ans = ans * (p + (nd == 0)) % mod; ld = nd; } bool g = N > 0; for (int i = 0; i < N; i++) if (D[i] != 9) g = 0; if (g) ans = (ans + mod - 1) % mod; printf ("%lld\n", ans); return 0; }