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

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

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

k = A("k")
h = B("h")
d = C("d")
b = C("b")

k.x = h
h.z = k
h.x = b
h.y = b
d.o = b
b.o = d
assert h.y.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

k = A("k")
h = B("h")
d = C("d")
b = C("b")

k.x = h
h.z = k
h.x = b
h.y = b
d.o = b
b.o = d
assert h.y.o.o.o.txt == "d"