import sys

input = lambda : sys.stdin.readline().rstrip()



import heapq

h = []

heapq.heapify(h)



n, m, s = list(map(int, input().split()))

a, b = [[None] * m for _ in range(2)]

c, d = [[None] * n for _ in range(2)]



ns = {u: [] for u in range(n)}

uv2e = {}

for i in range(m):

    u,v,a[i],b[i] = list(map(int, input().split()))

    ns[u-1].append(v-1)

    ns[v-1].append(u-1)

    uv2e[u-1,v-1] = i

    uv2e[v-1,u-1] = i

for i in range(n):

    c[i], d[i] = list(map(int, input().split()))



maxs = max(a)*(n-1)

s = min(s, maxs)

state = (0, 0, s) # (距離, ノード, 銀貨枚数)

ans = [[None] * (maxs+1) for _ in range(n)]

ans[0][s] = 0

done = [[None] * (maxs+1) for _ in range(n)]

heapq.heappush(h, state)

count = 0

while h:

    count += 1

    dd, u, ss = heapq.heappop(h)

#     if ans[u][ss] is not None and ans[u][ss] <= dd:

#         continue

#     ans[u][ss] = dd

    

    if done[u][ss]:

        continue

    done[u][ss] = True

    

    # グラフの隣接点

    for v in ns[u]:

        e= uv2e[u,v]

        if ss<a[e] or done[v][ss-a[e]] :

            continue

        ans[v][ss-a[e]] = min(ans[v][ss-a[e]], dd + b[e]) if ans[v][ss-a[e]] is not None else dd+b[e]

#         if ss<a[e] or ans[v][ss-a[e]] is not None:

#             continue

        heapq.heappush(h, (dd + b[e], v, ss-a[e]))

    # 両替

    if ss+c[u] <= maxs:

        sss = ss+c[u]

    elif ss < maxs:

        sss = maxs

    else:

        continue

    heapq.heappush(h, (dd + d[u], u, sss))

#     print(sss, maxs, ss, c[u])

    ans[u][sss] = min(ans[u][sss], dd + d[u]) if ans[u][sss] is not None else dd+d[u]



for item in ans[1:]:

    print((min(item)))
import sys

input = lambda : sys.stdin.readline().rstrip()



import heapq

from collections import defaultdict

h = []

heapq.heapify(h)



n, m, s = list(map(int, input().split()))

a, b = [[None] * m for _ in range(2)]

c, d = [[None] * n for _ in range(2)]



ns = defaultdict(list)

uv2e = {}

for i in range(m):

    u,v,a[i],b[i] = list(map(int, input().split()))

    ns[u-1].append(v-1)

    ns[v-1].append(u-1)

    uv2e[u-1,v-1] = i

    uv2e[v-1,u-1] = i

for i in range(n):

    c[i], d[i] = list(map(int, input().split()))



maxs = max(a)*(n-1)

s = min(s, maxs)

state = (0, 0, s) # (距離, ノード, 銀貨枚数)

ans = [[None] * (maxs+1) for _ in range(n)]

heapq.heappush(h, state)

count = 0

while h:

    count += 1

    dd, u, ss = heapq.heappop(h)

#     print(dd, u, ss)

    if ans[u][ss] is not None and ans[u][ss] <= dd:

        continue

    ans[u][ss] = dd

    

    # グラフの隣接点

    for v in ns[u]:

        e= uv2e[u,v]

        if ss<a[e] or ans[v][ss-a[e]] is not None:

            continue

        heapq.heappush(h, (dd + b[e], v, ss-a[e]))

    # 両替

    if ss+c[u] <= maxs:

        heapq.heappush(h, (dd + d[u], u, ss+c[u]))

    elif ss < maxs:

        heapq.heappush(h, (dd + d[u], u, maxs))



for item in ans[1:]:

    print((min(item)))

import sys

input = lambda: sys.stdin.readline().rstrip()
import heapq

h = []
heapq.heapify(h)
n, m, s = list(map(int, input().split()))
a, b = [[None] * m for _ in range(2)]
c, d = [[None] * n for _ in range(2)]
ns = {u: [] for u in range(n)}
uv2e = {}
for i in range(m):
    u, v, a[i], b[i] = list(map(int, input().split()))
    ns[u - 1].append(v - 1)
    ns[v - 1].append(u - 1)
    uv2e[u - 1, v - 1] = i
    uv2e[v - 1, u - 1] = i
for i in range(n):
    c[i], d[i] = list(map(int, input().split()))
maxs = max(a) * (n - 1)
s = min(s, maxs)
state = (0, 0, s)  # (距離, ノード, 銀貨枚数)
ans = [[None] * (maxs + 1) for _ in range(n)]
ans[0][s] = 0
done = [[None] * (maxs + 1) for _ in range(n)]
heapq.heappush(h, state)
count = 0
while h:
    count += 1
    dd, u, ss = heapq.heappop(h)
    #     if ans[u][ss] is not None and ans[u][ss] <= dd:
    #         continue
    #     ans[u][ss] = dd
    if done[u][ss]:
        continue
    done[u][ss] = True
    # グラフの隣接点
    for v in ns[u]:
        e = uv2e[u, v]
        if ss < a[e] or done[v][ss - a[e]]:
            continue
        ans[v][ss - a[e]] = (
            min(ans[v][ss - a[e]], dd + b[e])
            if ans[v][ss - a[e]] is not None
            else dd + b[e]
        )
        #         if ss<a[e] or ans[v][ss-a[e]] is not None:
        #             continue
        heapq.heappush(h, (dd + b[e], v, ss - a[e]))
    # 両替
    if ss + c[u] <= maxs:
        sss = ss + c[u]
    elif ss < maxs:
        sss = maxs
    else:
        continue
    heapq.heappush(h, (dd + d[u], u, sss))
    #     print(sss, maxs, ss, c[u])
    ans[u][sss] = min(ans[u][sss], dd + d[u]) if ans[u][sss] is not None else dd + d[u]
for item in ans[1:]:
    print((min(item)))

import sys

input = lambda: sys.stdin.readline().rstrip()
import heapq
from collections import defaultdict

h = []
heapq.heapify(h)
n, m, s = list(map(int, input().split()))
a, b = [[None] * m for _ in range(2)]
c, d = [[None] * n for _ in range(2)]
ns = defaultdict(list)
uv2e = {}
for i in range(m):
    u, v, a[i], b[i] = list(map(int, input().split()))
    ns[u - 1].append(v - 1)
    ns[v - 1].append(u - 1)
    uv2e[u - 1, v - 1] = i
    uv2e[v - 1, u - 1] = i
for i in range(n):
    c[i], d[i] = list(map(int, input().split()))
maxs = max(a) * (n - 1)
s = min(s, maxs)
state = (0, 0, s)  # (距離, ノード, 銀貨枚数)
ans = [[None] * (maxs + 1) for _ in range(n)]
heapq.heappush(h, state)
count = 0
while h:
    count += 1
    dd, u, ss = heapq.heappop(h)
    #     print(dd, u, ss)
    if ans[u][ss] is not None and ans[u][ss] <= dd:
        continue
    ans[u][ss] = dd
    # グラフの隣接点
    for v in ns[u]:
        e = uv2e[u, v]
        if ss < a[e] or ans[v][ss - a[e]] is not None:
            continue
        heapq.heappush(h, (dd + b[e], v, ss - a[e]))
    # 両替
    if ss + c[u] <= maxs:
        heapq.heappush(h, (dd + d[u], u, ss + c[u]))
    elif ss < maxs:
        heapq.heappush(h, (dd + d[u], u, maxs))
for item in ans[1:]:
    print((min(item)))

+from collections import defaultdict -ns = {u: [] for u in range(n)} +ns = defaultdict(list) -ans[0][s] = 0 -done = [[None] * (maxs + 1) for _ in range(n)] -    #     if ans[u][ss] is not None and ans[u][ss] <= dd: -    #         continue -    #     ans[u][ss] = dd -    if done[u][ss]: +    #     print(dd, u, ss) +    if ans[u][ss] is not None and ans[u][ss] <= dd: -    done[u][ss] = True +    ans[u][ss] = dd -        if ss < a[e] or done[v][ss - a[e]]: +        if ss < a[e] or ans[v][ss - a[e]] is not None: -        ans[v][ss - a[e]] = ( -            min(ans[v][ss - a[e]], dd + b[e]) -            if ans[v][ss - a[e]] is not None -            else dd + b[e] -        ) -        #         if ss<a[e] or ans[v][ss-a[e]] is not None: -        #             continue -        sss = ss + c[u] +        heapq.heappush(h, (dd + d[u], u, ss + c[u])) -        sss = maxs -    else: -        continue -    heapq.heappush(h, (dd + d[u], u, sss)) -    #     print(sss, maxs, ss, c[u]) -    ans[u][sss] = min(ans[u][sss], dd + d[u]) if ans[u][sss] is not None else dd + d[u] +        heapq.heappush(h, (dd + d[u], u, maxs))