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

#DSU0000020. Mạng không dây (Wireless Network)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Mạng không dây (Wireless Network)

Wireless Network

Source: POJ

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn computers, all initially broken, at fixed points in the plane. Two repaired computers can communicate directly if their Euclidean distance is at most dd. They may also communicate through other repaired computers.

Process operations that repair a computer or check whether two computers can communicate.

Input

The first line contains two integers n,dn,d. Each of the next nn lines contains two integers xi,yix_i,y_i, the coordinates of computer ii (numbered from 11). The next line contains an integer qq, the number of operations. Each of the following qq lines is one of:

  • O p: repair computer pp.
  • S a b: ask whether computers aa and bb can communicate.

Output

For each S operation, print SUCCESS if both computers are repaired and can communicate, and FAIL otherwise, one answer per line.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le 15; 0≤q≤500\le q\le 50; 0≤d≤200000\le d\le 20000; 0≤xi,yi≤100000\le x_i,y_i\le 10000; 1≤p,a,b≤n1\le p,a,b\le n.
  • Subtask 2 (30 points): 1≤n≤1501\le n\le 150; 0≤q≤100000\le q\le 10000; 0≤d≤200000\le d\le 20000; 0≤xi,yi≤100000\le x_i,y_i\le 10000; 1≤p,a,b≤n1\le p,a,b\le n.
  • Subtask 3 (50 points): 1≤n≤10011\le n\le 1001; 0≤q≤2990000\le q\le 299000; 0≤d≤200000\le d\le 20000; 0≤xi,yi≤100000\le x_i,y_i\le 10000; 1≤p,a,b≤n1\le p,a,b\le n.

Examples

Input

4 1
0 1
0 2
0 3
0 4
6
O 1
O 2
O 4
S 1 4
O 3
S 1 4

Output

FAIL
SUCCESS

Explanation

After repairing 1,2,4, computer 4 cannot reach 1, so print FAIL. Repairing 3 connects the chain 1–2–3–4, giving SUCCESS.