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

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

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

f = A("f")
c = B("c")
e = C("e")
m = A("m")
g = C("g")
d = A("d")
j = A("j")
h = A("h")

f.o = j
c.o = f
c.w = f
c.z = m
e.x = g
e.z = g
m.o = d
g.x = e
g.z = e
d.o = j
j.o = d
h.o = j
assert j.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

f = A("f")
c = B("c")
e = C("e")
m = A("m")
g = C("g")
d = A("d")
j = A("j")
h = A("h")

f.o = j
c.o = f
c.w = f
c.z = m
e.x = g
e.z = g
m.o = d
g.x = e
g.z = e
d.o = j
j.o = d
h.o = j
assert j.o.o.o.o.o.txt == "d"