There are N cities numbered 1 to N, connected by M railroads.

You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket.

The i-th railroad connects City U_i and City V_i bidirectionally, and a one-way trip costs A_i silver coins and takes B_i minutes. You cannot use gold coins to pay the fare.

There is an exchange counter in each city. At the exchange counter in City i, you can get C_i silver coins for 1 gold coin. The transaction takes D_i minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter.

For each t=2, ..., N, find the minimum time needed to travel from City 1 to City t. You can ignore the time spent waiting for trains.

Constraints

* 2 \leq N \leq 50
* N-1 \leq M \leq 100
* 0 \leq S \leq 10^9
* 1 \leq A_i \leq 50
* 1 \leq B_i,C_i,D_i \leq 10^9
* 1 \leq U_i < V_i \leq N
* There is no pair i, j(i \neq j) such that (U_i,V_i)=(U_j,V_j).
* Each city t=2,...,N can be reached from City 1 with some number of railroads.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N M S
U_1 V_1 A_1 B_1
:
U_M V_M A_M B_M
C_1 D_1
:
C_N D_N


Output

For each t=2, ..., N in this order, print a line containing the minimum time needed to travel from City 1 to City t.

Examples

Input

3 2 1
1 2 1 2
1 3 2 4
1 11
1 2
2 5


Output

2
14


Input

4 4 1
1 2 1 5
1 3 4 4
2 4 2 2
3 4 1 1
3 1
3 1
5 2
6 4


Output

5
5
7


Input

6 5 1
1 2 1 1
1 3 2 1
2 4 5 1
3 5 11 1
1 6 50 1
1 10000
1 3000
1 700
1 100
1 1
100 1


Output

1
9003
14606
16510
16576


Input

4 6 1000000000
1 2 50 1
1 3 50 5
1 4 50 7
2 3 50 2
2 4 50 4
3 4 50 3
10 2
4 4
5 5
7 7


Output

1
3
5


Input

2 1 0
1 2 1 1
1 1000000000
1 1


Output

1000000001
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();
    }
}