class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: A = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.o: A = None
        self.x: C = None
        self.txt = txt

j = A("j")
m = B("m")
n = C("n")
f = C("f")
g = A("g")

j.u = g
m.o = g
m.z = g
n.o = j
n.x = f
f.o = j
f.x = n
g.u = j
assert m.o.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: A = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.o: A = None
        self.x: C = None
        self.txt = txt

j = A("j")
m = B("m")
n = C("n")
f = C("f")
g = A("g")

j.u = g
m.o = g
m.z = g
n.o = j
n.x = f
f.o = j
f.x = n
g.u = j
assert m.o.u.u.txt == "g"