



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

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 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
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()