A series/parallel resistor circuit is shown below.

The resistance value is written next to each resistor. A connection point (a wire joining two or more resistors together) is denoted by an uppercase letter. The letters A and Z are reserved for the two connection points that are the endpoints of the circuit. Our goal is to compute the equivalent resistance of the circuit, i.e., the equivalent resistance between A and Z.
Within the circuit, a resistor can be specified by a triple consisting of the connection points at its two endpoints together with its resistance. For example, the resistor labelled $9$ could be specified as either $(C, D, 9)$ or $(D, C, 9)$. A circuit specification is the set of all its resistor specifications.
Two resistors are in series if they share a common connection point that is used by no other resistor (for example, resistors $6$ and $9$ are both connected to $C$, and nothing else is connected to $C$). Two series resistors can be replaced by a single equivalent resistor whose resistance is the sum of the two (in the example, $15$).
Two resistors are in parallel if both of their endpoints are common connection points (for example, resistors $3$ and $10$ are both connected to $R$ and to $D$). Two parallel resistors can be replaced by a single equivalent resistor whose resistance is the inverse of the sum of the inverses of the two resistances (in the example, $\left(\frac{1}{3} + \frac{1}{10}\right)^{-1} = 2.307692$).

The equivalent resistance of a well-formed series-parallel circuit can be found by repeatedly replacing a series or parallel pair with its single equivalent resistor until only one resistor remains. If this technique gets stuck before reaching a single resistor, the circuit is not well-formed. For instance, a Wheatstone Bridge circuit (shown below) is not a well-formed series-parallel circuit.

There may be several circuit specifications. For each circuit, the first line is an integer $N$ ($N \le 1000$), the number of resistors in the circuit. It is followed by $N$ lines, each a resistor specification of the form:
X Y r
where $X$ and $Y$ are uppercase letters and $r$ is a positive integer resistance ($r < 100$). The equivalent resistance is guaranteed never to exceed $100$. A line containing a single $0$ terminates the input.
For each circuit, if it is well-formed and reduces to a single equivalent resistance between $A$ and $Z$, print that equivalent resistance rounded to and shown with exactly $3$ decimal places. If the circuit is not well-formed, or if there is no equivalent resistance between $A$ and $Z$, print -1.000 instead. Do not print blank lines between outputs.