using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC164E_2
{
    class Program
    {
        static void Main(string[] args)
        {
            long INF = long.MaxValue / 2;

            var N = RInt;
            var M = RInt;
            var S = RLong;

            List<Edge>[] edges = new List<Edge>[N].Select(x => new List<Edge>()).ToArray();
            for (int i = 0; i < M; i++)
            {
                var u = RInt - 1;
                var v = RInt - 1;
                var a = RInt;
                var b = RInt;
                edges[u].Add(new Edge() { to = v, cost = a, time = b });
                edges[v].Add(new Edge() { to = u, cost = a, time = b });
            }

            int[] C = new int[N];
            int[] D = new int[N];
            for (int i = 0; i < N; i++)
            {
                C[i] = RInt;
                D[i] = RInt;
            }

            long[,] minTime = new long[N, 50 * N];
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < 50 * N; j++)
                {
                    minTime[i, j] = INF;
                }
            }
            if (S >= 50 * N) S = 50 * N - 1;
            minTime[0, S] = 0;

            Queue<State> que = new Queue<State>();
            que.Enqueue(new State() { now = 0, cost = S});
            while (que.Count() > 0)
            {
                var from = que.Dequeue();

                foreach (var e in edges[from.now])
                {
                    //辺遷移
                    long c1 = from.cost - e.cost;
                    long t1 = minTime[from.now, from.cost] + e.time;
                    if (c1 >= 0 && minTime[e.to, c1] > t1)
                    {
                        minTime[e.to, c1] = t1;
                        que.Enqueue(new State() { now = e.to, cost = c1});
                    }

                    //点遷移
                    long c2 = from.cost + C[from.now];
                    long t2 = minTime[from.now, from.cost] + D[from.now];
                    if (c2 < 50 * N && c2 >= 0 && minTime[from.now, c2] > t2)
                    {
                        minTime[from.now, c2] = t2;
                        que.Enqueue(new State() { now = from.now, cost = c2});
                    }
                }
            }

            //Draw2D(minTime);

            for (int i = 1; i < N; i++)
            {
                long ans = INF;
                for (int j = 0; j < 50 * N; j++)
                {
                    ans = Math.Min(ans, minTime[i, j]);
                }
                Console.WriteLine(ans);
            }
        }

        public struct State
        {
            public int now;
            public long cost;
        }

        public struct Edge
        {
            public int to;
            public long cost;
            public long time;
        }
    }
}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(long[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            long[,] map2 = new long[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 31384