// Arup Guha
// 7/23/2025
// Solution to Kattis Problem: Shortest Path 1
// https://open.kattis.com/problems/shortestpath1

import java.util.*;

public class shortestpath1 {

	public static void main(String[] args) {
	
		// Get basic input for first case.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int m = stdin.nextInt();
		int q = stdin.nextInt();
		int s = stdin.nextInt();
		
		// Process cases.
		while (n != 0) {
		
			// Set up graph.
			ArrayList<edge>[] g = new ArrayList[n];
			for (int i=0; i<n; i++)
				g[i] = new ArrayList<edge>();
			
			// Read edges.
			for (int i=0; i<m; i++) {
				int u = stdin.nextInt();
				int v = stdin.nextInt();
				int w = stdin.nextInt();
				g[u].add(new edge(u, v, w));
			}
			
			// Run dijkstra's. dist[i] = shortest distance from s to i.
			// We'll do -1 for unreachable.
			int[] dist = dijkstras(g, s);
			
			// Handle queries.
			for (int i=0; i<q; i++) {
				int dest = stdin.nextInt();
				
				// This is what they want.
				if (dist[dest] == -1)
					System.out.println("Impossible");
				else
					System.out.println(dist[dest]);
			}
		
			// Get next case.
			n = stdin.nextInt();
			m = stdin.nextInt();
			q = stdin.nextInt();
			s = stdin.nextInt();
			
			// Annoying...
			if (n > 0) System.out.println();
		}
	}
	
	// Runs Dijkstra's from the source vertex s and returns all the shortest distances from s.
	public static int[] dijkstras(ArrayList<edge>[] g, int s) {
	
		// Set up distance array.
		int n = g.length;
		int[] dist = new int[n];
		
		Arrays.fill(dist, -1);
		dist[s] = 0;
		
		// Will store who we already have shortest distances to.
		boolean[] used = new boolean[n];
		int numDone = 0;
		
		// Set up priority queue.
		PriorityQueue<edge> pq = new PriorityQueue<edge>();
		pq.offer(new edge(s, s, 0));
		
		// Keep going
		while (pq.size() > 0 && numDone < n) {
		
			// Get the next estimate.
			edge cur = pq.poll();
			
			// We already know this shortest distance.
			if (used[cur.v]) continue;
			
			// We have proof this is a shortest distance.
			used[cur.v] = true;
			dist[cur.v] = cur.w;
			numDone++;
			
			// Loop through all edges leaving v.
			for (edge next: g[cur.v])
				if (dist[next.v] == -1 || cur.w + next.w < dist[next.v])
					pq.offer(new edge(s, next.v, cur.w + next.w));
			
		}
		
		return dist;
	}
}

class edge implements Comparable<edge> {

	public int u;
	public int v;
	public int w;
	
	public edge(int myu, int myv, int myw) {
		u = myu;
		v = myv;
		w = myw;
	}	
	
	public int compareTo(edge other) {
		if (this.w != other.w) return this.w-other.w;
		if (this.u != other.u) return this.u - other.u;
		return this.v - other.v;
	}
}