#P7193. Luka's Kiss

    ID: 20397 Type: Default 1000ms 256MiB

Luka's Kiss

Luka's Kiss

Luka parked his truck by the lake. Barica lives in the lake and leaps from one floating plant to another. There are n plants floating on the lake, each defined by a pair of coordinates. Barica is initially on the first plant given in the input.

Barica can jump from a plant at \( (x,y) \) in one of four diagonal directions. In any jump she may choose a positive integer \( p \) and then, according to the direction, she attempts to land on the plant at:

  • Direction A: \( (x+p,\; y+p) \)
  • Direction B: \( (x+p,\; y-p) \)
  • Direction C: \( (x-p,\; y+p) \)
  • Direction D: \( (x-p,\; y-p) \)

Barica chooses a direction (the moves are given in order in the input) and then jumps to the first plant along that ray, that is, the one for which \( p \) is the smallest positive integer making \( (x \pm p,\; y \pm p) \) equal to a plant's coordinate. If there is no plant in the selected direction, she stays on her current plant.

After she jumps, the plant she jumped from disappears. Luka wants to know the final coordinates of the plant where Barica ends up so that he can wait there to kiss her and turn her into a beautiful princess!

inputFormat

The first line contains an integer \( n \) (the number of plants). The following \( n \) lines each contain two integers \( x \) and \( y \), representing the coordinates of a plant. The first plant in the list is where Barica starts.

The next line contains an integer \( m \) (the number of moves). Each of the following \( m \) lines contains a single character: A, B, C, or D, indicating the direction of the jump.

outputFormat

Output the final coordinates of the plant where Barica ends up, in the format: x y.

sample

4
0 0
1 1
2 2
3 3
2
A
A
2 2