import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



from functools import lru_cache



L,A,B,MOD = list(map(int,read().split()))



@lru_cache(None)

def F(r,n,MOD):

    # 1+r+...+r^{n-1} をダブリングで求める

    if n == 0:

        return 0

    q = n//2

    x = F(r,q,MOD)

    # 1+r^qをかける

    x *= 1 + pow(r,q,MOD); x %= MOD

    if n&1:

        x *= r; x += 1; x %= MOD

    return x



@lru_cache(None)

def G(r,n,MOD):

    # sum ir^i をダブリングで求める

    if n == 0:

        return 0

    q = n//2

    x = G(r,q,MOD)

    # 1+r^qをかける

    x *= 1 + pow(r,q,MOD); x %= MOD

    # q(r^q+...+r^{2q-1})を加える

    x += F(r,q,MOD) * pow(r,q,MOD) * q % MOD

    if n&1:

        x *= r; x += F(r,n,MOD); x -= 1; x %= MOD

    return x



S = 0

for d in range(1,20):

    # d桁の最初、最後、項数

    lower = 10**(d-1)

    upper = 10**d-1

    # lower <= A+nB <= upper

    nlower = (lower-A+B-1)//B

    nupper = (upper-A)//B

    if nlower < 0:

        nlower = 0

    if nupper >=L:

        nupper = L-1

    if nlower > nupper:

        continue

    items = nupper - nlower + 1

    r = (10**d) % MOD

    last = A+B*nupper

    x = last * F(r,items,MOD)

    x -= B * G(r,items,MOD)

    length = d*items

    S *= pow(10,length,MOD); S += x

    S %= MOD



print(S)



import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



L,A,B,MOD = list(map(int,read().split()))



def geom_seq_sum(r,n,MOD):

    """

    return \sum_{i=0}^{n-1} r^i mod MOD

    """

    if r == 1:

        return n%MOD

    r1 = r-1

    return ((pow(r,n,r1*MOD)-1)//r1)% MOD



def geom_seq_sum_1(r,n,MOD):

    """

    return \sum_{i=0}^{n-1} ir^i mod MOD

    """

    if r == 1:

        return n*(n-1)//2%MOD

    r1 = r-1

    x = pow(r,n,r1*r1*MOD)

    return (-(x-1)//r1 + (n-1)*x + 1)//r1 % MOD



S = 0

for d in range(1,20):

    # d桁の最初、最後、項数

    lower = 10**(d-1)

    upper = 10**d-1

    # lower <= A+nB <= upper

    nlower = (lower-A+B-1)//B

    nupper = (upper-A)//B

    if nlower < 0:

        nlower = 0

    if nupper >=L:

        nupper = L-1

    if nlower > nupper:

        continue

    items = nupper - nlower + 1

    r = (10**d) % MOD

    last = A+B*nupper

    x = last * geom_seq_sum(r,items,MOD)

    x -= B * geom_seq_sum_1(r,items,MOD)

    length = d*items

    S *= pow(10,length,MOD); S += x

    S %= MOD



print(S)
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import lru_cache

L, A, B, MOD = list(map(int, read().split()))


@lru_cache(None)
def F(r, n, MOD):
    # 1+r+...+r^{n-1} をダブリングで求める
    if n == 0:
        return 0
    q = n // 2
    x = F(r, q, MOD)
    # 1+r^qをかける
    x *= 1 + pow(r, q, MOD)
    x %= MOD
    if n & 1:
        x *= r
        x += 1
        x %= MOD
    return x


@lru_cache(None)
def G(r, n, MOD):
    # sum ir^i をダブリングで求める
    if n == 0:
        return 0
    q = n // 2
    x = G(r, q, MOD)
    # 1+r^qをかける
    x *= 1 + pow(r, q, MOD)
    x %= MOD
    # q(r^q+...+r^{2q-1})を加える
    x += F(r, q, MOD) * pow(r, q, MOD) * q % MOD
    if n & 1:
        x *= r
        x += F(r, n, MOD)
        x -= 1
        x %= MOD
    return x


S = 0
for d in range(1, 20):
    # d桁の最初、最後、項数
    lower = 10 ** (d - 1)
    upper = 10**d - 1
    # lower <= A+nB <= upper
    nlower = (lower - A + B - 1) // B
    nupper = (upper - A) // B
    if nlower < 0:
        nlower = 0
    if nupper >= L:
        nupper = L - 1
    if nlower > nupper:
        continue
    items = nupper - nlower + 1
    r = (10**d) % MOD
    last = A + B * nupper
    x = last * F(r, items, MOD)
    x -= B * G(r, items, MOD)
    length = d * items
    S *= pow(10, length, MOD)
    S += x
    S %= MOD
print(S)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
L, A, B, MOD = list(map(int, read().split()))


def geom_seq_sum(r, n, MOD):
    """
    return \sum_{i=0}^{n-1} r^i mod MOD
    """
    if r == 1:
        return n % MOD
    r1 = r - 1
    return ((pow(r, n, r1 * MOD) - 1) // r1) % MOD


def geom_seq_sum_1(r, n, MOD):
    """
    return \sum_{i=0}^{n-1} ir^i mod MOD
    """
    if r == 1:
        return n * (n - 1) // 2 % MOD
    r1 = r - 1
    x = pow(r, n, r1 * r1 * MOD)
    return (-(x - 1) // r1 + (n - 1) * x + 1) // r1 % MOD


S = 0
for d in range(1, 20):
    # d桁の最初、最後、項数
    lower = 10 ** (d - 1)
    upper = 10**d - 1
    # lower <= A+nB <= upper
    nlower = (lower - A + B - 1) // B
    nupper = (upper - A) // B
    if nlower < 0:
        nlower = 0
    if nupper >= L:
        nupper = L - 1
    if nlower > nupper:
        continue
    items = nupper - nlower + 1
    r = (10**d) % MOD
    last = A + B * nupper
    x = last * geom_seq_sum(r, items, MOD)
    x -= B * geom_seq_sum_1(r, items, MOD)
    length = d * items
    S *= pow(10, length, MOD)
    S += x
    S %= MOD
print(S)

-from functools import lru_cache - -@lru_cache(None) -def F(r, n, MOD): -    # 1+r+...+r^{n-1} をダブリングで求める -    if n == 0: -        return 0 -    q = n // 2 -    x = F(r, q, MOD) -    # 1+r^qをかける -    x *= 1 + pow(r, q, MOD) -    x %= MOD -    if n & 1: -        x *= r -        x += 1 -        x %= MOD -    return x +def geom_seq_sum(r, n, MOD): +    """ +    return \sum_{i=0}^{n-1} r^i mod MOD +    """ +    if r == 1: +        return n % MOD +    r1 = r - 1 +    return ((pow(r, n, r1 * MOD) - 1) // r1) % MOD -@lru_cache(None) -def G(r, n, MOD): -    # sum ir^i をダブリングで求める -    if n == 0: -        return 0 -    q = n // 2 -    x = G(r, q, MOD) -    # 1+r^qをかける -    x *= 1 + pow(r, q, MOD) -    x %= MOD -    # q(r^q+...+r^{2q-1})を加える -    x += F(r, q, MOD) * pow(r, q, MOD) * q % MOD -    if n & 1: -        x *= r -        x += F(r, n, MOD) -        x -= 1 -        x %= MOD -    return x +def geom_seq_sum_1(r, n, MOD): +    """ +    return \sum_{i=0}^{n-1} ir^i mod MOD +    """ +    if r == 1: +        return n * (n - 1) // 2 % MOD +    r1 = r - 1 +    x = pow(r, n, r1 * r1 * MOD) +    return (-(x - 1) // r1 + (n - 1) * x + 1) // r1 % MOD -    x = last * F(r, items, MOD) -    x -= B * G(r, items, MOD) +    x = last * geom_seq_sum(r, items, MOD) +    x -= B * geom_seq_sum_1(r, items, MOD)