from collections import deque
# DFS (재귀)
def dfs(v, visited):
visited[v] = True
print(v, end=' ')
for next_v in graph[v]:
if not visited[next_v]:
dfs(next_v, visited) #재귀호출을 한다
# BFS (큐)
def bfs(start):
visited = [False] * (N + 1)
queue = deque([start])
visited[start] = True
#큐가 끝날 때 까지 탐색을 계속한다
while queue:
v = queue.popleft()
print(v, end=' ')
for next_v in graph[v]:
if not visited[next_v]:
visited[next_v] = True #방문처리를 한다
queue.append(next_v) #다음에 방문할 예정이므로 큐에 추가한
# 입력을 받는다. V는 정점이다
N, M, V = map(int, input().split())
graph = [[] for _ in range(N + 1)]
# 간선을 입력받는다
for _ in range(M):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
#정점끼리 서로 연결해준다
# 각 정점의 인접 리스트를 정렬한다
for i in range(1, N + 1):
graph[i].sort()
# DFS 실행
visited = [False] * (N + 1)
dfs(V, visited)
print()
# BFS 실행
bfs(V)
S = input().strip()
for i in range(len(S)):
# S[i:]가 팰린드롬인지 검사한다
#가장 앞에서부터 맨 끝의 문자까지와 순서대로 비교한다
if S[i:] == S[i:][::-1]:
# i개의 문자를 뒤에 붙이면 완성
print(len(S) + i)
break