S = input()
l = len(S)
mod = int(1e9) + 7

'''def saiki(s):
  if s == "0":
    return 1
  elif s == "1":
    return 3
  else:
    if s[0] == '0':
      return saiki(s[1:])
    else:
      SS = 2*saiki(s[1:]) + 3 ** (len(s) - 1)
      return SS'''

cnt = int(S[l-1]) * 2 + 1
base = 3
for i in range(l-1, 0, -1):
  x = int(S[i-1])
  cnt *= x+1
  cnt += base * int(x)
  cnt %= mod
  base *= 3
  base %= mod
print(cnt) S = input() S input() input l = len(S) l len(S) len S mod = int(1e9) + 7 mod int(1e9) + 7 int(1e9) int 1e9 7 '''def saiki(s):
  if s == "0":
    return 1
  elif s == "1":
    return 3
  else:
    if s[0] == '0':
      return saiki(s[1:])
    else:
      SS = 2*saiki(s[1:]) + 3 ** (len(s) - 1)
      return SS''' cnt = int(S[l-1]) * 2 + 1 cnt int(S[l-1]) * 2 + 1 int(S[l-1]) * 2 int(S[l-1]) int S[l-1] S l-1 l 1 2 1 base = 3 base 3 for i in range(l-1, 0, -1):
  x = int(S[i-1])
  cnt *= x+1
  cnt += base * int(x)
  cnt %= mod
  base *= 3
  base %= mod i range(l-1, 0, -1) range l-1 l 1 0 -1 x = int(S[i-1]) x int(S[i-1]) int S[i-1] S i-1 i 1 cnt *= x+1 cnt x+1 x 1 cnt += base * int(x) cnt base * int(x) base int(x) int x cnt %= mod cnt mod base *= 3 base 3 base %= mod base mod print(cnt) print cnt base %= mod mod base mod = int(1e9) + 7 int(1e9) + 7 mod x = int(S[i-1]) int(S[i-1]) x l = len(S) len(S) l cnt = int(S[l-1]) * 2 + 1 int(S[l-1]) * 2 + 1 cnt cnt *= x+1 x+1 cnt cnt += base * int(x) base * int(x) cnt base *= 3 3 base S = input() input() S base = 3 3 base cnt %= mod mod cnt
S = input()
l = len(S)
mod = int(1e9) + 7

'''def saiki(s):
  if s == "0":
    return 1
  elif s == "1":
    return 3
  else:
    if s[0] == '0':
      return saiki(s[1:])
    else:
      SS = 2*saiki(s[1:]) + 3 ** (len(s) - 1)
      return SS'''

cnt = int(S[l-1]) * 2 + 1
base = 3
for i in range(l-1, 0, -1):
  x = int(S[i-1])
  cnt *= x+1
  cnt += base * int(x)
  cnt %= mod
  base *= 3
  base %= mod
print(cnt)