import sys from collections import defaultdict as dd input = sys.stdin.readline N = int(input()) ls = list(map(int, input().split())) rs = list(map(int, input().split())) ds = list(map(int, input().split())) mod = 10 ** 9 + 7 d = [0] * N d[0] = ds[0] for i in range(N - 1): d[i + 1] = ds[i + 1] - ds[i] print(d) res = 1 zeros = 0 for i in range(N): if zeros == 1 and (d[i] == 0): continue zeros = d[i] == 0 l = ls[i] r = rs[i] t = (pow(10, r, mod) - 1) * pow(9, mod - 2, mod) % mod if l: t -= (pow(10, l, mod) - 1) * pow(9, mod - 2, mod) % mod res *= t + (d[i] == 0) * (i > 0) res %= mod print(res)