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

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

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

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

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

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

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

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

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