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

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

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

m = A("m")
d = B("d")
l = C("l")
j = A("j")
k = C("k")

m.z = d
m.r = d
d.o = l
l.r = d
l.w = d
l.o = j
j.z = d
j.r = d
k.r = d
k.w = d
k.o = m
assert j.z.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.r: B = None
        self.txt = txt

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

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

m = A("m")
d = B("d")
l = C("l")
j = A("j")
k = C("k")

m.z = d
m.r = d
d.o = l
l.r = d
l.w = d
l.o = j
j.z = d
j.r = d
k.r = d
k.w = d
k.o = m
assert j.z.o.w.txt == "d"