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

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

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

f = A("f")
e = B("e")
m = C("m")
k = A("k")

f.z = e
f.w = k
e.o = m
e.v = m
e.q = k
m.r = k
m.o = f
m.q = f
k.z = e
k.w = f
assert f.z.v.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.w: A = None
        self.txt = txt

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

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

f = A("f")
e = B("e")
m = C("m")
k = A("k")

f.z = e
f.w = k
e.o = m
e.v = m
e.q = k
m.r = k
m.o = f
m.q = f
k.z = e
k.w = f
assert f.z.v.o.z.txt == "e"