You are given Q tuples of integers (L, A, B, M). For each tuple, answer the following question. 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 * 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?

Constraints:
- All values in input are integers.
- 1 <= L, A, B < 10^18
- 2 <= M <= 10^9
- All terms in the arithmetic progression are less than 10^18.

Input:
Input is given from Standard Input in the following format:
L A B M

Output:
Print the remainder when the integer obtained by concatenating the terms is divided by M.

Sample Input 1:
5 3 4 10007

Sample Output 1:
5563
Our arithmetic progression is 3, 7, 11, 15, 19, so the answer is 37111519 mod 10007, that is, 5563.

Sample Input 2:
4 8 1 1000000

Sample Output 2:
891011

Sample Input 3:
107 10000000000007 1000000000000007 998244353

Sample Output 3:
39122908

# Buggy version:
def matrix_product(X,Y,M):
    XY = [[0]*3 for _ in range(3)]

    for i in range(3):
        for j in range(3):
            for k in range(3):
                XY[i][j] += X[i][k]*Y[k][j] % M
            XY[i][j] %= M
    
    return XY

def power(X,n,M):
    res = [[1,0,0],[0,1,0],[0,0,1]]

    if n == 0: return res

    while n > 0:
        if n & 1: res = matrix_product(res,X,M)
        X = matrix_product(X,X,M)
        n //= 2
    
    return res

L, A, B, M = map(int,input().split())

X = [0,A,1]

for d in range(1,19):
    if L == 0: break

    
    l = (10**(d-1) - A + B-1) // B
    r = (10**d - A) // B
    if (10**d - A) % B == 0: r -= 1
    
    if l < 0: l = 0
    if r < 0: r = -1
    print("{0} {1}".format(l,r))

    
    C = min(r-l+1,L)
    L -= C
    print(C)

    Y = power([[10**d,0,0],[1,1,0],[0,B,1]],C,M)
    
    next_X = [0,0,0]
    for i in range(3):
        for j in range(3):
            next_X[i] += X[j] * Y[j][i] % M
        next_X[i] %= M
    X = next_X

print(X[0])

# Fixed version:
def matrix_product(X,Y,M):
    XY = [[0]*3 for _ in range(3)]

    for i in range(3):
        for j in range(3):
            for k in range(3):
                XY[i][j] += X[i][k]*Y[k][j] % M
            XY[i][j] %= M
    
    return XY

def power(X,n,M):
    res = [[1,0,0],[0,1,0],[0,0,1]]

    if n == 0: return res

    while n > 0:
        if n & 1: res = matrix_product(res,X,M)
        X = matrix_product(X,X,M)
        n //= 2
    
    return res

L, A, B, M = map(int,input().split())

X = [0,A,1]

for d in range(1,19):
    if L == 0: break

    
    l = (10**(d-1) - A + B-1) // B
    r = (10**d - A) // B
    if (10**d - A) % B == 0: r -= 1
    
    if l < 0: l = 0
    if r < 0: r = -1
    
    C = min(r-l+1,L)
    L -= C

    Y = power([[10**d,0,0],[1,1,0],[0,B,1]],C,M)
    
    next_X = [0,0,0]
    for i in range(3):
        for j in range(3):
            next_X[i] += X[j] * Y[j][i] % M
        next_X[i] %= M
    X = next_X

print(X[0])

# Buggy version:
import sys
sys.setrecursionlimit(pow(10, 6))
# input = sys.stdin.readline

import numpy as np

def pow_matmul(r, n, m):
  if n == 1:
    return r
  if n % 2 == 0:
    _r = pow_matmul(r, n//2, m)
    return np.mod(np.dot(_r, _r), m)
  else:
    _r = pow_matmul(r, n//2, m)
    _r = np.mod(np.dot(_r, _r), m)
    return np.mod(np.dot(r, _r), m)

def main():
  l, a, b, m = map(int, input().split())
  c = [min(max(0, (10**i - a - 1) // b + 1), l) for i in range(19)]
  ans = 0
  r = np.ones((3,3))
  s = np.array([0, a%m, 1])

  for d in range(1, 19):
    dnum = c[d] - c[d-1]
    if dnum==0:
      continue
    r_s = np.array([[pow(10, d, m), 1, 0], [0, 1, (b%m)], [0, 0, 1]])
    r = pow_matmul(r_s, dnum, m)
    s = np.mod(np.dot(r, s), m)
    print(d, r, s)
    if c[d] > l:
      break
  print(s[0])


if __name__ == '__main__':
  main()


# Fixed version:
import sys
sys.setrecursionlimit(pow(10, 6))
# input = sys.stdin.readline

import numpy as np

def pow_matmul(r, n, m):
  if n == 1:
    return r
  if n % 2 == 0:
    _r = pow_matmul(r, n//2, m)
    return np.mod(np.dot(_r, _r), m)
  else:
    _r = pow_matmul(r, n//2, m)
    _r = np.mod(np.dot(_r, _r), m)
    return np.mod(np.dot(r, _r), m)

def main():
  l, a, b, m = map(int, input().split())
  c = [min(max(0, (10**i - a - 1) // b + 1), l) for i in range(19)]
  ans = 0
  r = np.ones((3,3))
  s = np.array([0, a%m, 1])

  for d in range(1, 19):
    dnum = c[d] - c[d-1]
    if dnum==0:
      continue
    r_s = np.array([[pow(10, d, m), 1, 0], [0, 1, (b%m)], [0, 0, 1]])
    r = pow_matmul(r_s, dnum, m)
    s = np.mod(np.dot(r, s), m)
    if c[d] > l:
      break
  print(s[0])


if __name__ == '__main__':
  main()

# Buggy version:
import math
import numpy as np
from decimal import *
L,A,B,M=map(int, input().split())

def matpow(X,n,mod):
  E = np.eye(N=X.shape[0],dtype=int)
  Y = X%mod
  if n == 1:
    return Y
  else:
    return np.dot(matpow(np.dot(Y,Y)%mod,n//2,mod), (Y if n % 2 else E))%mod
  
a = 0
for d in range(1,19):
  left = math.ceil(Decimal(10**(d-1)-A)/Decimal(B))
  right = math.ceil(Decimal(10**d-A)/Decimal(B))-1
  if right < 0:
    continue
  if left > L-1:
    break
  if left > right:
    continue
  if left < 0:
    left = 0
  if right > L-1:
    right = L-1
  print(d,left,right)
  mat = np.matrix([[10**d,0,0],[1,1,0],[0,1,1]])
  result = np.dot(np.array([a,A+B*left,B])%M, matpow(mat,right-left+1,M))
  a = result[0,0]%M
  
print(a)

# Fixed version:
import math
import numpy as np
from decimal import *
L,A,B,M=map(int, input().split())

def matpow(X,n,mod):
  E = np.eye(N=X.shape[0],dtype=int)
  Y = X%mod
  if n == 1:
    return Y
  else:
    return np.dot(matpow(np.dot(Y,Y)%mod,n//2,mod), (Y if n % 2 else E))%mod
  
a = 0
for d in range(1,19):
  left = math.ceil(Decimal(10**(d-1)-A)/Decimal(B))
  right = math.ceil(Decimal(10**d-A)/Decimal(B))-1
  if right < 0:
    continue
  if left > L-1:
    break
  if left > right:
    continue
  if left < 0:
    left = 0
  if right > L-1:
    right = L-1
  mat = np.matrix([[10**d,0,0],[1,1,0],[0,1,1]])
  result = np.dot(np.array([a,A+B*left,B])%M, matpow(mat,right-left+1,M))
  a = result[0,0]%M
  
print(a)