{
TASK: NYKSTUKAIJ
LANG: PASCAL
}
program nykstukai;

  const PRF = 'NAMAS.DAT';
        RZF = 'NAMAS.REZ';
        MAX_K = 10;
        MAx_S = 10;
  type Tvmas = array [1..MAX_S] of integer;
       Tdmas = array [1..MAX_K, 1..MAX_K] of boolean;

  var K, S, { kambariø ir nykðtukø skaièius }
       t, t1, isej: integer;
       dur: Tdmas; { durø masyvas }
       nyk: Tvmas;

  procedure begti (var buta: Tvmas);
    var i, j, tt: integer;
  begin
    for i := 1 to K do
      buta[i] := 0;
    if t1 <= t
       then begin
              buta[isej] := t1;
              tt := t1;
            end
       else exit; { per maþai laiko iðeiti ið namo }
    while tt + t1 <= t do
      begin
        for i := 1 to K do
          for j := 1 to K do
            if (buta[i]=tt) and (buta[j]=0) and dur[i, j]
               then  buta[j] := buta[i]+t1;
        tt := tt + t1;
      end;
  end; { bëgti }

  function pabegs (buta: Tvmas): integer;
    var kiek, i: integer;
  begin
    kiek := 0;
    for i := 1 to S do
      if buta[nyk[i]] > 0
         then kiek := kiek + 1;
    pabegs := kiek;
  end; { pabëgs }

  procedure skaityti (var S, K, ISEJ, t, t1: integer;
                      var nyk: Tvmas; var dur: Tdmas);
    var f: text;
        i, j, k1, k2, D: integer;
  begin
    assign (f, PRF);
    reset (f);
    readln (f, S, D);
    readln (f, K);
    readln (f, ISEJ);
    readln (f, t, t1);
    for i := 1 to S do
      readln (f, nyk[i]);
    for i := 1 to K do
      for j := 1 to K do
        dur[i, j] := false;
    for i := 1 to D do
      begin
        readln (f, k1, k2);
        dur[k1, k2] := true;
        dur[k2, k1] := true;
      end;
    close (f);
  end; { skaityti }

  procedure rasyti (kiek: integer; buta: Tvmas);
    var f: text;
        i: integer;
  begin
    assign (f, RZF);
    rewrite (f);
    writeln (f, kiek);
    for i := 1 to S do
      if buta[nyk[i]]>0
         then writeln (f, i);
    close (f);
  end; { raðyti }

  var buta: Tvmas;
      kiek: Integer;
begin
  skaityti (S, K, isej, t, t1, nyk, dur);
  begti (buta);
  kiek := pabegs (buta);
  rasyti (kiek, buta);
end.
