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.*;
import java.util.*;
import java.math.*;
import java.awt.Point;
 
public class Main {
	//static final long MOD = 998244353L;
	//static final long INF = 1000000000000000007L;
	static final long MOD = 1000000007L;
	static final int INF = 1000000007;
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.ni();
		int M = sc.ni();
		int S = Math.min(sc.ni(),9999);
		int[][] edges = new int[M][4];
		for (int i = 0; i < M; i++) {
			edges[i] = new int[]{sc.ni()-1,sc.ni()-1,sc.ni(),sc.ni()};
		}
		int[][] ex = new int[N][2];
		for (int i = 0; i < N; i++) {
			ex[i] = new int[]{sc.ni(),sc.ni()};
		}
		ArrayList<Edge>[] graph = new ArrayList[10000*N];
		for (int i = 0; i < graph.length; i++)
			graph[i] = new ArrayList<Edge>();
		
		for (int i = 0; i < N; i++) {
			for (int m = 0; m < 10000; m++) {
				int n1 = 10000*i+m;
				int n2 = 10000*i+Math.min(9999, m+ex[i][0]);
				graph[n1].add(new Edge(n1,n2,ex[i][1]));
			}
		}
		
		for (int[] e: edges) {
			for (int m = e[2]; m < 10000; m++) {
				int n1 = 10000*e[0]+m;
				int n2 = 10000*e[0]+m-e[2];
				int n3 = 10000*e[1]+m;
				int n4 = 10000*e[1]+m-e[2];
				graph[n1].add(new Edge(n1,n4,e[3]));
				graph[n3].add(new Edge(n3,n2,e[3]));
			}
		}
		
		PriorityQueue<Pair> pq = new PriorityQueue<Pair>();
		long[] distances = new long[10000*N];
		Arrays.fill(distances,Long.MAX_VALUE);
		distances[S] = 0;
		pq.add(new Pair(S,0L));
		while (! pq.isEmpty()) {
			Pair temp = pq.poll();
			int parent = temp.node;
			for (Edge e: graph[parent]) {
				int child = e.to;
				if (distances[child] > distances[parent] + e.time) {
					distances[child] = distances[parent] + e.time;
					pq.add(new Pair(child,distances[child]));
				}
			}
		}
		long[] ans = new long[N];
		for (int i = 0; i < N; i++) {
			long v = Long.MAX_VALUE;
			for (int m = 0; m < 10000; m++) {
				v = Math.min(v,distances[10000*i+m]);
			}
			ans[i] = v;
		}
		for (int i = 1; i < N; i++)
			pw.println(ans[i]);
		
		pw.close();
	}
	
	static class Pair implements Comparable<Pair> {
		public int node;
		public long weight;
		
		public Pair(int n, long w) {
			node = n;
			weight = w;
		}
		
		public int compareTo(Pair p) {
			if (weight < p.weight)
				return -1;
			else
				return 1;
		}
	}
	
	static class Edge {
		public int from;
		public int to;
		public long time; //weight
		public Edge(int f, int t, long w) {
			from = f;
			to = t;
			time = w;
		}
	}
 
	public static long dist(long[] p1, long[] p2) {
		return (Math.abs(p2[0]-p1[0])+Math.abs(p2[1]-p1[1]));
	}
	
	//Find the GCD of two numbers
	public static long gcd(long a, long b) {
		if (a < b) return gcd(b,a);
		if (b == 0)
			return a;
		else
			return gcd(b,a%b);
	}
	
	//Fast exponentiation (x^y mod m)
	public static long power(long x, long y, long m) { 
		if (y < 0) return 0L;
		long ans = 1;
		x %= m;
		while (y > 0) { 
			if(y % 2 == 1) 
				ans = (ans * x) % m; 
			y /= 2;  
			x = (x * x) % m;
		} 
		return ans; 
	}
	
	public static int[] shuffle(int[] array) {
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		return array;
	}
	
	public static long[] shuffle(long[] array) {
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    long temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		return array;
	}
	
	public static int[][] shuffle(int[][] array) {
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		return array;
	}
	
    public static int[][] sort(int[][] array) {
    	//Sort an array (immune to quicksort TLE)
 
		Arrays.sort(array, new Comparator<int[]>() {
			  @Override
        	  public int compare(int[] a, int[] b) {
				  return a[0]-b[0]; //ascending order
	          }
		});
		return array;
	}
    
    public static long[][] sort(long[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    long[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<long[]>() {
			  @Override
        	  public int compare(long[] a, long[] b) {
				  if (a[0] < b[0])
					  return -1;
				  else if (a[0] > b[0])
					  return 1;
				  else
					  return 0;
	          }
		});
		return array;
	}
    
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }
        
        int ni() { 
            return Integer.parseInt(next()); 
        }
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() {
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}