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

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

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

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

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

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

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

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

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