import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;


public class Main {
	
	public static void main(String[] args) {
		new Main().run();
	}
	
	class Edge {
		int src,dst;
		long dist;
		int cost;
		public Edge(int src,int dst,long dist,int cost) {
			this.src=src;
			this.dst=dst;
			this.dist=dist;
			this.cost=cost;
		}
	}
	
	class State implements Comparable<State>{
		int v;
		long dist;
		int money;
		public State(int v,long dist,int money) {
			this.v=v;
			this.dist=dist;
			this.money=money;
		}
		@Override
		public int compareTo(State o) {
			if (dist!=o.dist) return Long.compare(dist, o.dist);
			else return -Integer.compare(money, o.money);
		}
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		int N=sc.nextInt();
		int M=sc.nextInt();
		int S=Math.min(sc.nextInt(),5000);
		ArrayList<Edge>[] g=new ArrayList[N];
		for (int i=0;i<N;++i) {
			g[i]=new ArrayList<>();
		}
		for (int i=0;i<M;++i) {
			int u=sc.nextInt()-1;
			int v=sc.nextInt()-1;
			int cost=sc.nextInt();
			long dist=sc.nextLong();
			g[u].add(new Edge(u,v,dist,cost));
			g[v].add(new Edge(v,u,dist,cost));
		}
		int[] C=new int[N];
		long[] D=new long[N];
		for (int i=0;i<N;++i) {
			C[i]=Math.min(5000, sc.nextInt());
			D[i]=sc.nextLong();
		}
		
		long INF=Long.MAX_VALUE/3;
		long[][] dist=new long[N][5001];
		for (int i=0;i<dist.length;++i) {
			for (int j=0;j<dist[i].length;++j) {
				dist[i][j]=INF;
			}
		}
		
		dist[0][S]=0;
		PriorityQueue<State> pq=new PriorityQueue<>();
		pq.add(new State(0,0,S));
		while (!pq.isEmpty()) {
			State state=pq.poll();
			if (dist[state.v][state.money] < state.dist) continue;
			for (Edge e:g[state.v]) {
				{
					int get=0;
					if (!(state.money+get*C[state.v]<e.cost)) {
						int nmoney=state.money+get*C[state.v]-e.cost;
						if (dist[e.dst][nmoney]>dist[state.v][state.money]+e.dist+get*D[state.v]) {
							dist[e.dst][nmoney]=dist[state.v][state.money]+e.dist+get*D[state.v];
							pq.add(new State(e.dst,dist[e.dst][nmoney],nmoney));
						}
					}
				}
				{
					int get=1;
					int nmoney=state.money+get*C[state.v];
					if (!(nmoney>5000)) { 
						if (dist[state.v][nmoney]>dist[state.v][state.money]+get*D[state.v]) {
							dist[state.v][nmoney]=dist[state.v][state.money]+get*D[state.v];
							pq.add(new State(state.v,dist[state.v][nmoney],nmoney));
						}
					}
				}
			}
		}
		
		for (int i=1;i<N;++i) {
			long ans=INF;
			for (int j=0;j<=5000;++j) {
				ans=Math.min(ans, dist[i][j]);
			}
			System.out.println(ans);
		}
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}




class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
    	return (int)nextLong();
    }
}

Measured memory_bytes: 62208