/*--------------------------------------------------------------*/
/* ACM ICPC 2009-2010, NEERC                                    */
/* Northern Subregional Contest                                 */
/* St Petersburg, October 17, 2009                              */
/*--------------------------------------------------------------*/
/* Problem K. Kripke Model                                      */
/*                                                              */
/* Original idea         Fedor Tsarev                           */
/* Problem statement     Fedor Tsarev                           */
/* Testset               Fedor Tsarev                           */
/*--------------------------------------------------------------*/
/* Solution                                                     */
/*                                                              */
/* Author                Sergey Kopeliovich                     */
/*--------------------------------------------------------------*/
 
#include <cstdio>
#include <vector>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define sz(a) (int)(a).size()

#define IS(a, c) ((is[a] >> (c)) & 1)

const int maxn = (int)1e4;

int cc = 0, x, y, n, m, is[maxn], bad[maxn], good[maxn];
vector <int> rc[maxn];

void dfs( int v )
{
  if (bad[v])
    return;
  bad[v] = 1;
  forn(i, sz(rc[v]))
    dfs(rc[v][i]);
}

void dfs2( int v )
{
  if (good[v])
    return;
  good[v] = 1, cc++;
  forn(i, sz(rc[v]))
    if (IS(rc[v][i], x))
      dfs2(rc[v][i]);  
}

int main()
{
//  freopen("kripke.in", "r", stdin);
//  freopen("kripke.out", "w", stdout);
  
  scanf("%d%d%*d", &n, &m);
  forn(i, n)
  {
    int k;
    scanf("%d", &k);
    while (k--)
    {
      char ch;
      scanf(" %c", &ch);
      is[i] |= 1 << (ch - 'a');
    }
  }
  while (m--)
  {
    int a, b;
    scanf("%d%d", &a, &b), a--, b--;
    rc[b].pb(a);
  }

  char form[99];
  scanf("%s", form);

  x = form[2] - 'a';
  y = form[7] - 'a';

  forn(i, n)
    if (!IS(i, y))
      dfs(i);
  forn(i, n)
    if (!bad[i])
      dfs2(i);

  printf("%d\n", cc);
  forn(i, n)
    if (good[i])
      printf("%d\n", i + 1);
  return 0;
}
