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

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

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

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

d.z = e
d.p = e
d.y = k
b.o = d
b.q = d
e.p = k
k.o = d
k.q = d
assert d.z.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.y: B = None
        self.p: C = None
        self.txt = txt

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

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

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

d.z = e
d.p = e
d.y = k
b.o = d
b.q = d
e.p = k
k.o = d
k.q = d
assert d.z.p.q.txt == "d"