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

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

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

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

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

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

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

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

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