PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000008. Điểm gặp của Miguel (Meeting Prof. Miguel)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Điểm gặp của Miguel (Meeting Prof. Miguel)

Meeting Prof. Miguel

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Two travellers have distinct road networks, one for young (Y) and another for mature (M). Roads may be one-way (U) or two-way (B). Find the minimum combined cost and all optimal meeting locations in alphabetic order.

Input

mm lines of age direction a b w, then the two initial locations.

Output

Print You will never meet. if impossible; otherwise print minimum cost followed by all optimal meeting letters.

Subtasks

  • Subtask 1 (40 points): m≤20m\le 20; 0≤m≤10000\le m\le 1000; 1≤w≤10001\le w\le 1000; A≤a,b≤ZA\le a,b\le Z.
  • Subtask 2 (60 points): 0≤m≤10000\le m\le 1000; 1≤w≤10001\le w\le 1000; A≤a,b≤ZA\le a,b\le Z.

Examples

Input

2
Y B A B 2
M B C B 3
A C

Output

5 B

Explanation

The young traveller uses A-B at cost 22; the mature traveller uses C-B at cost 33. They meet at B for total cost 55.