output_description: Print the remainder when the integer obtained by concatenating the terms is
  divided by M.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      L A B M
attempt: L, A, B, mod = map(int, input().split())
  
  
  def f(l):
      return max(0, (10**l - A - 1) // B + 1)
  
  
  def m(a, b):
      r = [[0] * len(b[0]) for i in range(len(a))]
      for i in range(len(a)):
          for k in range(len(b)):
              for j in range(len(b[0])):
                  r[i][j] = (r[i][j] + a[i][k] * b[k][j]) % mod
      return r
  
  
  def p(a, n):
      r = [[0] * len(a) for i in range(len(a))]
      b = []
      for i in range(len(a)):
          r[i][i] = 1
          b.append(a[i][:])
      l = n
      while l > 0:
          if l & 1:
              r = m(b, r)
          b = m(b, b)
          l >>= 1
      return r
  
  
  X = [[0, 0, 1], [0, 0, A], [0, 0, 0]]
  Y, R, Z = 0, 1, 0
  while L:
      Y = [[1, 0, 0], [B, 1, 0], [0, 1, pow(10, R, mod)]]
      Z = min(L, f(R) - f(R - 1))
      L -= Z
      Y = p(Y, Z)
      X = m(Y, X)
      R += 1
  print(X[2][2] % mod)
  
problem_description: Statement
  
  There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.
  
  The initial term is A, and the common difference is B. That is, s_i = A + B
  \times i holds.
  
  Consider the integer obtained by concatenating the terms written in base ten
  without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be
  concatenated into 37111519. What is the remainder when that integer is divided
  by M?
samples: [{"input": "5 3 4 10007", "output": "5563\n    \n\nOur arithmetic progression is 3, 7, 11, 15, 19, so the answer is 37111519 mod\n10007, that is, 5563.\n\n* * *"}, {"input": "4 8 1 1000000", "output": "891011\n    \n\n* * *"}, {"input": "107 10000000000007 1000000000000007 998244353", "output": "39122908"}]