#TEST1012. TCP/IP网络

TCP/IP网络

Background

The TCP/IPTCP/IP protocol is an important protocol in the field of network communication. Your task today is to try to utilize this protocol to restore a simplified network connection scenario.

Topic Description

In this problem, computers are divided into two main categories: Server and Client. Servers are responsible for setting up the network and Clients are responsible for joining the network.

There are a total of nn computers, numbered 1n1 \sim n, that need to make a network connection, and these machines will initiate a single operation to establish a network or join a network, in increasing order of number.

Each machine is required to provide an address string when attempting to establish or join a network. The address string supplied by a server machine represents the address at which it is attempting to establish a network, and the address string supplied by a client machine represents the address at which it is attempting to join a network.

A conforming address string should have the following characteristics:

  1. must be of the form a.b.c.d:e, where a,b,c,d,ea, b, c, d, e are non-negative integers;
  2. 0a,b,c,d2550 \le a, b, c, d \le 255, 0e655350 \le e \le 65535;
  3. a,b,c,d,ea, b, c, d, e cannot contain a redundant leading 00.

Accordingly, an address string that does not conform to the specification may have the following characteristics:

  1. it is not a string of the form a.b.c.d:e, e.g., it contains more than 33 characters . or more than 11 characters :, etc. 2. the integers $a, b, c, d:e`;
  2. one or more of the integers a,b,c,d,ea, b, c, d, e is outside the above range;
  3. one or more of the integers a,b,c,d,ea, b, c, d, e contains a redundant leading 00.

For example, the address string 192.168.0.255:80 is conformant, but the address strings 192.168.0.999:80, 192.168.02.1:10, 192.168.0.1:088, 192:168:0:1.233, 47.120.30.163:8080:1234, 1..1..1..1:1.233, 47.120.30.163:8080:1234, 1..1..1::1, ... .111111:111111 are all out of specification.

If the address string provided by the server or client when initiating the operation does not conform to the specification, this operation will simply be ignored.

In this problem, we assume that any address string that meets the above specification can participate in a normal connection, and you do not need to consider the actual meaning of each address string.

For reasons such as network blocking, two servers are not allowed to use the same address string, and if this happens, the latter server attempting to establish a network will not be able to do so successfully; otherwise, any server providing an address string that conforms to the specification will be able to establish a network successfully.

If a client providing an address that conforms to the specification provides the same address string as a previous server that has successfully established the network when it tries to join the network, this client can successfully join the network and is said to be connected to this server; if no such server can be found, it is assumed that this client cannot successfully join the network.

Note that while it is not allowed for two different servers to use the same address string, it is allowed for multiple clients to use the same address string, and for the same server to be connected to by multiple clients at the same time.

Your task is simple: given the type of each computer and the address string, determine how connected this computer is.

Input format

First line, a positive integer nn (3n10003 \le n \le 1000).

The next nn lines, two strings op,ad\mathit{op}, \mathit{ad} per line, give the type and address string of each computer, numbered from smallest to largest.

Where op\mathit{op} is guaranteed to be one of the strings Server or Client, and ad\mathit{ad} is a string up to 2525 in length consisting only of numbers, the characters . and the character :.

The two strings on each line are separated by exactly one space, and there are no extra spaces at the end of each line.

Output format

The output consists of nn lines, each with a positive integer or string indicating the connection status of the iith computer. where:

If the iith computer is a server:

  1. if it provides a canonical address string and successfully establishes the network, output the string OK. 2. if it provides a canonical address string and successfully establishes the network, output the string OK.
  2. if it provides an address string that matches the specification, but is unable to successfully establish the network due to a previous server with the same address string, output the string FAIL. 3. if it provides an address string that matches the specification and successfully establishes the network, output the string OK.
  3. if it provides an address string that is not a conforming address string, output the string ERR.

If the iith computer is a client:

  1. if it provides an address string that conforms to the specification and successfully joins the network, output a positive integer indicating the number of the server to which this client is connected.
  2. output the string FAIL if it provides an address string that matches the specification, but is unable to join the network successfully. 3.
  3. output the string ERR if it provides an address string that does not conform to the specification.

``input1 5 Server 192.168.1.1:8080 Server 192.168.1.1:8080 Client 192.168.1.1:8080 Client 192.168.1.1:8080 Client 192.168.1.1:99999

```output1
Client 192.168.1.1:80 Client 192.168.1.1:80
Client 192.168.1.1:99999
FAIL
1
FAIL
ERR
ERR
10
Server 192.168.1.1:80
Client 192.168.1.1:80
Client 192.168.1.1:8080
Server 192.168.1.1:80
Server 192.168.1.1:8080
Server 192.168.1.999:0
Client 192.168.1.1.8080
Client 192.168.1.1:8080
Client 192.168.1.1:8080
Client 192.168.1.999:0
Client 192.168.1.1:80 Client 192.168.1.999:0
Client 192.168.1.1:80
1
FAIL
FAIL
FAIL
ERR
ERR
ERR
ERR 5
ERR

Tip.

[Sample Explanation #1]

Computer 11, a server, provides the canonical address string 192.168.1.1:8080 and successfully establishes a network;

Computer 22, a server, provides the same address string as computer 11 and fails to successfully establish a network;

Computer 33, a client, provides the canonical address string 192.168.1.1:8080, successfully joins the network, and connects to server 11;

Computer 44 is a client, providing the canonical address string 192.168.1.1:80, and cannot find a server to connect to it;

Computer 55 is a client and provided a non-conforming address string 192.168.1.1:99999.