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 for i in range(N): l = ls[i] r = rs[i] if d[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 else: res *= 1 res %= mod print(res)