using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public struct Edge
{
	public long To;
	public long Silver;
	public long Time;

	public Edge(long to, long silver, long time)
	{
		To = to;
		Silver = silver;
		Time = time;
	}
}

public class E { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		long M = GetLong();
		long S = GetLong();
		var adj = Range(0, N).Select(_ => new List<Edge>()).ToArray();
		for(long i = 0; i < M; i++)
		{
			long U = GetLong() - 1;
			long V = GetLong() - 1;
			long A = GetLong();
			long B = GetLong();
			adj[U].Add(new Edge(V, -A, B));
			adj[V].Add(new Edge(U, -A, B));
		}
		for(long i = 0; i < N; i++)
			adj[i].Add(new Edge(i, GetLong(), GetLong()));

		long SMax= 2525;
		long inf = long.MaxValue / 2;
		var dp = new long[N, SMax + 1];
		for(long i = 0; i < N; i++)
		{
			for(long j = 0; j <= SMax; j++)
				dp[i, j] = inf;
		}

		Comparison<(long, long, long)> comp = ((x, y) => x.Item1.CompareTo(y.Item1));
		var pq = new PriorityQueue<(long, long, long)>(N * SMax + 1, comp);

		long iniSilver = Min(S, SMax);
		dp[0, iniSilver] = 0;
		pq.Push((0, 0, iniSilver));

		while(pq.Count > 0)
		{
			var p = pq.Pop();
			long cost = p.Item1;
			long v = p.Item2;
			long s = p.Item3;
			if(dp[v, s] < cost)
				continue;

			foreach(var edge in adj[v])
			{
				long nextSilver = Min(SMax, s + edge.Silver);
				if(nextSilver < 0)
					continue;
				
				long nextCost = dp[v, s] + edge.Time;
				if(dp[edge.To, nextSilver] > nextCost)
				{
					dp[edge.To, nextSilver] = nextCost;
					pq.Push((nextCost, edge.To, nextSilver));
				}
			}			
		}

		var ans = new List<long>();
		for(long i = 1; i < N; i++)
		{
			long min = long.MaxValue;
			for(long j = 0; j <= SMax; j++)
				chmin(ref min, dp[i, j]);

			ans.Add(min);
		}
		WriteLine(string.Join("\n", ans));
	}
}

public class PriorityQueue<T>
{
	public long Count { get; private set; } = 0;
	public long MaxSize { get; private set; } = 0;
	private T[] m_heap;
	private Comparison<T> Comp = null;
	
	public PriorityQueue(long maxSize, Comparison<T> comp)
	{
		if(maxSize <= 0)
			throw new Exception();
		MaxSize = maxSize;
		m_heap = new T[maxSize];

		Comp = comp;
	}
	
	public void Push(T x)
	{
		if(Count == MaxSize)
		{
			T[] new_heap = new T[MaxSize << 1];
			Array.Copy(m_heap, new_heap, MaxSize);
			m_heap = new_heap;
			MaxSize <<= 1;
		}
		
		long i = Count++;
		while(i > 0)
		{
			long p = (i - 1)/2;
			if(Comp(m_heap[p], x) <= 0)
				break;
			m_heap[i] = m_heap[p];
			i = p;			
		}
		m_heap[i] = x;		
	}
	
	public T Pop()
	{
		if(Count == 0)
			throw new Exception("Queue is empty.");
		
		T result = m_heap[0];
		T x = m_heap[--Count];
		long i = 0;
		while(i * 2 + 1 < Count)
		{
			long c1 = i * 2 + 1, c2 = i * 2 + 2;
			if(c2 < Count && Comp(m_heap[c2], m_heap[c1]) < 0)
				c1 = c2;
			if(Comp(m_heap[c1], x) >= 0)
				break;
			m_heap[i] = m_heap[c1];
			i = c1;
		}
		m_heap[i] = x;
		
		return result;		
	}
	
	public T Peek() => m_heap[0];
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 31216